c读取文件保存到mysql



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);
    
    
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值