mysqllongtext:在Mysql中用 LONGTEXT 类型存储大文件来源: 发布时间:星期日, 2009年8月16日 浏览:4次 评论:0
// MySql2.cpp : Defines the entry po
![]() // # ![]() //是前 ![]() ![]() //代码来自网络 ![]() ![]() ![]() ![]() ![]() //需要设置为你自己 ![]() //在DBMS中线要创建数据库www ![]() ![]() //测试文件c:\\test.iso ![]() ![]() ![]() ![]() ![]() ![]() ![]() //最大测试过加入文件大小为650M( ![]() ![]() //注意:还要修改my.ini文件中 ![]() ![]() ![]() //max_allowed_packet = 1024M //# ![]() //# ![]() //# ![]() //# ![]() // ![]() # ![]() # ![]() # ![]() # ![]() # ![]() # ![]() # ![]() # ![]() # ![]() # ![]() # ![]() ![]() #pragma comment(lib,"libmysql.lib") //得到文件 ![]() ![]() { struct stat file_stats; ![]() ![]() *size = file_stats.st_size; ![]() } ![]() ![]() ![]() ![]() { char *filename=NULL; off_t size; MYSQL *conn=NULL; MYSQL_RES *res_ ![]() MYSQL_ROW row; MYSQL_FIELD *field=NULL; ![]() char *sql; //sql语句 FILE *fp; char *buf; ![]() char *end; unsigned long *length; /* ![]() { pr ![]() exit(1); } */ filename = "c:\\test.iso"; ![]() ![]() ![]() { perror("get file size" ); exit(1); } ![]() ![]() ![]() { perror("malloc buf" ); exit(1); } ![]() ![]() { perror("fopen file" ); exit(1); } ![]() { perror("fread file" ); exit(1); } sql = (char *)malloc( ![]() ![]() ![]() { perror("malloc sql" ); exit(1); } conn = mysql_init(NULL);//生产 ![]() ![]() ![]() { pr ![]() exit(1); } ![]() ![]() { pr ![]() exit(1); } strcpy(sql, "insert ![]() end = sql; end ![]() ![]() //convert NUL(ASCII 0)、'\n'、'\r'、'\'’、'''、'"'和Control-Z and so _disibledevent=>end ![]() ![]() *end ![]() *end ![]() flag = mysql_real_query(conn, sql, (unsigned ![]() ![]() { pr ![]() exit(1); } ![]() { pr ![]() exit(1); } res_ ![]() fclose(fp); fp = NULL; fp = fopen("c:\\123.iso", "wb" ); while ((row = mysql_fetch_row(res_ ![]() { length = mysql_fetch_lengths(res_ ![]() for (i=0; i<mysql_num_fields(res_ ![]() ![]() { fwrite(row[0], 1, length[0], fp); //pr ![]() } } fclose(fp); mysql_close(conn); free(sql); free(buf); sql = NULL; ![]() } 运行结果: ![]() 0
相关文章
读者评论发表评论 |