mysql c api mysql query function dosn't work
NickName:Iman Ask DateTime:2017-08-02T14:19:05

mysql c api mysql query function dosn't work

I spend 3 hours to figure out what is my problem in this code and why mysql_query doesn't work... this is my query:

`sprintf(quer, "INSERT INTO `tblRobotProcessQueue`(ProcessId,Protocol,SRC_IP,DST_IP,SRC_Port,DST_Port,`HostName`,`URL`,`Href`,DateAdd) VALUES(%d,%d,%d,%d,%d,%d,%s,%s,%s,%d )" ,pid*i, 6, 1234, 5345, 80, 44, "HostName", "URL", "Href", currentTime);` 

and here is my customize db_query :

int _db_query(MYSQL *mysql_conn, char* sql ) {
    int ret = 0;

    if ( 0 == ( ret = mysql_ping( mysql_conn ) ) ) {

        if(!mysql_query( mysql_conn , sql )){
            PTRACE(0,0, "mysql_query can't run");
        }

        printf("ret is : %d\n", ret);

        //syslog ( LOG_INFO , "db_query( %u , [%s] )" , connection_id , sql );
        if ( 0 != ret && NULL != mysql_error( mysql_conn ) ) {

            syslog ( LOG_INFO , "Mysql query connection %s", mysql_error( mysql_conn ) );
            PTRACE(0,0, "FAIL HERE IN _DB_QUERY");
        }

    } else {
        PTRACE( 0 , 0 , "Mysql Ping Error connection %s" ,mysql_error( mysql_conn ) );

    }
    PTRACE(0,0, "reach to end of _db_query...\n");
    return ret;
}

when i run my program i can see some data added in my table with phpmysqladnin
but this part execute in my terminal: PTRACE(0,0, "mysql_query can't run");
help me guys!

Copyright Notice:Content Author:「Iman」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45452870/mysql-c-api-mysql-query-function-dosnt-work

More about “mysql c api mysql query function dosn't work” related questions

mysql c api mysql query function dosn't work

I spend 3 hours to figure out what is my problem in this code and why mysql_query doesn't work... this is my query: `sprintf(quer, "INSERT INTO `tblRobotProcessQueue`(ProcessId,Protocol,SRC_IP,D...

Show Detail

MySQL C API mysql_query

I have two problems with the MySQL C API. How do I get variable to be added to the table when I do the mysql_query() and how do I get the table show decimals? Here is my code: void insertDataToT...

Show Detail

mysql c api limit function

mysql_query(conn,"SELECT abstract FROM papers limit 4 "); Can we use variables in limit function in C-api.Like I have to iteratively extract 10 rows,so something of the form: mysql_query(conn,"

Show Detail

load mysql dump in database using mysql C API

I want to manage a database in C language. So I am using C API for mysql. I am unable to find a function in C API for loading the a .sql file directly to mysql. I have gone through documentation bu...

Show Detail

MySQL C API using results

I am using the MySQL C API to query the database and I have the results stored in MYSQL_ROW types. I am able to print the results to the console with printf("%s", row[0]); however, according to ...

Show Detail

How to set a timeout for MySQL query using C API

I know there are lots of similar questions here, also there are lots of results, when I google it, but none of them answers my question. I read this, this, this and this but none of them works for ...

Show Detail

Syntax for input parameters in a MySQL query using the C API

This is exactly my question but in using the C API for MySQL: Syntax for input parameters in a MySQL query How do I parameterize a C query? What I attempted in doing, though it fails: int statu...

Show Detail

C API mysql not returning result set

I have a situation where I am making serial SELECT queries to a table on a LAMP box using the C api. The first query select a single record (an order header). The second query then uses the returned

Show Detail

Problem with handling the result of SELECT query in MYSQL C API

I'm getting a Internal Server Error with one of my scripts. I'm using MYSQL C API. https://dev.mysql.com/doc/refman/5.6/en/c-api.html Here is the corresponding part of my script: MYSQL *con; MYS...

Show Detail

MySQL C API custom values

I have been working with the tutorial on MySQL C API from http://zetcode.com/tutorials/mysqlcapitutorial/ the following example is working fine: #include <my_global.h> #include <mysql.h&g...

Show Detail