FILE *fp;
int fileLen;
char fileName[500];
char *dbuffer;
char *escape_object = NULL;
char *sql;
unsigned int mescape_size;
int sql_len;
char *bufs;
fp = fopen(fileName,"rb");
if(NULL == fp)
{
MessagePopup("Error","Could not find the file");
goto Error;
}
fseek(fp,0L,SEEK_END); //文件结尾
fileLen=ftell(fp);//获取文件长度
escape_object = (char *)malloc(fileLen+1);
if( escape_object == NULL ){
MessagePopup("error","malloc..");
goto Error;
}
fseek(fp,0L,SEEK_SET); //文件开头
fread(escape_object,fileLen,1,fp);
escape_object[fileLen]=0;
//dbuffer空的char指针
dbuffer= (char *)malloc(sizeof(char)*(fileLen+1));
mescape_size = 2 * size + 2;
sql = (char *)malloc(sizeof(char)*mescape_size*2+256);
bufs= (char *)malloc(sizeof(char)*(size+1));
//mysqlConn 是 MYSQL mysqlConn;mysql数据库连接
/**数据库连接
mysql_init(&mysqlConn);
//mysql_real_connect(&mysql,"localhost", "root", "123456", "databaseName",0,NULL,0)
if (!(mysql_real_connect(&mysqlConn,strSQLSource,strSQLUser, strSQLPassword, strDBName,0,NULL,0)))
{
MessagePopup("Message",mysql_error(&mysqlConn));
}
*/
mescape_size = mysql_real_escape_string(&mysqlConn,bufs,escape_object, mescape_size);
//mysql查询语句
sql_len=sprintf(sqls,"update %s set FileName='%s',FileData='%s' where code='%s'",tables,filename,escape_object,code);
//查询方法
mysql_real_query(&mysqlConn, sql, sql_len);