http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=71276

解决方案 »

  1.   

    paul dubois 的mysql网络数据库指南就有(机械工业出版社)把源码贴出来,省得你查了.
    #include    <windows.h>
    #include <stdio.h>
    #include <string.h>
    #include <mysql.h>
    void load_image (MYSQL *conn, FILE *f)
    {
    char query[1024*200], buf[1024*100], *p;
    unsigned long from_len; sprintf(query,"insert into  blobtest (blobtest) values ( \'" );
    p = query + strlen (query);
    while ((from_len = fread (buf, 1, sizeof (buf), f)) > 0)
    {
    if (p + (2*from_len) + 3 > query + sizeof (query))
    {
    printf("image too big");
    return ;
    }
    p += mysql_real_escape_string (conn, p, buf, from_len);
    }
    *p++ = '\'';
    *p++ = ')';
    strcpy(p," where img_id=1");
    mysql_real_query (conn, query, (unsigned long) (p- query));
    }void main ()
    {
    char *opt_host_name = "192.168.1.253";
    char *opt_user_name = "root";
    char *opt_password = NULL;
    unsigned int opt_port_num = 3306;
    char *opt_socket_name = NULL;
    char *opt_db_name = "test";
    unsigned int opt_flags = 0;
    MYSQL *conn; FILE *f; conn = mysql_init (NULL); mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password,
    opt_db_name, opt_port_num, opt_socket_name, opt_flags);

    if ((f = fopen ("c:/test1.JPG", "rb")) == NULL)
    {
    printf("file open eror!");
    return ;
    }
    load_image (conn, f);
    fclose(f); mysql_close (conn);
    return;
    }
      

  2.   

    呵呵,
    最简单的办法SELECT Col_Blob FROM tA INTO DUMPFILE "C:/123.ZIP"
    如果使用 INTO DUMPFILE 代替 INTO OUTFILE,MySQL 将在文件中只写一行,没任何列或行端接和任何转义。如果你希望存储一个 blob 列到文件中,这是非常有用的。 当然最好是通过 流操作来实现