I can't get the following code to work. It's working with normal select or insert, but when I try to insert a variable to it it didn't work. Can some let me know please what's wrong here?
Please note that the output is below.
int main(int argc, char **argv)
{
MYSQL *conn;
char str[100] = "test";
conn = mysql_init(NULL);
char stmt_buf[100];
sprintf (stmt_buf, "insert into test values ('%s')", str);
printf("\n%s\n",stmt_buf);
mysql_query (conn, stmt_buf);
mysql_close(conn);
return 0;
}
~$./version
insert into test values ('test')
Segmentation fault
gdb ./version->rungcc -Wall -g), to improve your code till no warnings are given by the compiler, and to use a debugger (e.g.gdb)??connis0x0.