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