The codes below inserts values into MYSQL database. If i use "sprintf(Query, "INSERT into t(d) values (%c)", a);" it wont insert the word hello into my database. i have also tried using (%s) in the above statement. However, if i use "sprintf(Query, "INSERT into t(d) values (%d)", b);" it inserts the values 1234 into the database.
What is happening? Why wont it insert character's or string into my database but only integers?
The column d is my database is defined as char type.
Thanks.
#include "stdafx.h"
#include <stdio.h>
#include <mysql.h>
//#include <string>
//using std::string;
//#include <atlstr.h>
MYSQL *pConnection;
MYSQL_RES *pResult=NULL;
MYSQL_ROW Row;
char Query[256];
int main(int argc, char* argv[])
{
pConnection = mysql_init(NULL);
mysql_real_connect(pConnection,"localhost","root","y123","test",0,NULL,0);
char a[] ="Hello";
int b = 1234;
printf("%s", a);
sprintf(Query, "INSERT into t(d) values (%s)", a);
mysql_query(pConnection, Query);
}