InBlock.gifAPI:http: //dev.mysql.com/doc/refman/5.1/zh/apis.html
InBlock.gif
数据库:mysql
InBlock.gif开发工具:vc6.0
InBlock.gif1、设置Project Settings下的C/C++,选择Category的CodeGeneration,设置use run-time library为Multithreaded,原因是数据库需要使用到多线程
InBlock.gif
2、设置Tools下Options的Directories选项,将mysql安装目录下的include文件夹路径加入Include files,或者直接将include文件夹下的mysql.h拷到工程目录下,然后缺什么文件,放心,编译器会叫的
InBlock.gif
3、将mysql目录下\lib\opt中的libmysql.lib拷到工程目录下
InBlock.gif

InBlock.gif#include <winsock2.h>
InBlock.gif#include <stdio.h>
InBlock.gif#include "mysql.h"
InBlock.gif#pragma comment(lib, "libmysql.lib")
InBlock.gif int main()
InBlock.gif{
InBlock.gif        MYSQL mysql;
InBlock.gif        mysql_init(&mysql);
InBlock.gif         if(mysql_real_connect(&mysql, "localhost", "root", "123456", "test", 0, NULL, CLIENT_MULTI_STATEMENTS) != NULL)
InBlock.gif        {
InBlock.gif                printf( "客户端版本信息:%s\n", mysql_get_client_info());
InBlock.gif                printf( "客户端版本信息:%u\n", mysql_get_client_version());
InBlock.gif                printf( "描述连接的字符串:%s\n", mysql_get_host_info(&mysql));
InBlock.gif                printf( "服务器的版本号:%u\n", mysql_get_server_version(&mysql));
InBlock.gif                printf( "连接所使用的协议版本:%u\n", mysql_get_proto_info(&mysql));
InBlock.gif                printf( "服务器的版本号:%u\n", mysql_get_server_info(&mysql));
InBlock.gif
                mysql_real_query(&mysql, "select * from user", sizeof( "select * from user")-1);
InBlock.gif                MYSQL_RES *res;
InBlock.gif                 if((res = mysql_use_result(&mysql)) == NULL)
InBlock.gif                { /*如果查询未返回结果集,mysql_store_result()将返回Null指针(例如,如果查询是INSERT语句)。
InBlock.gif                        如果读取结果集失败,mysql_store_result()还会返回Null指针。通过检查mysql_error()是否返回非空字符串,mysql_errno()是否返回非0值,或mysql_field_count()是否返回0,可以检查是否出现了错误。
InBlock.gif                        如果未返回行,将返回空的结果集。(空结果集设置不同于作为返回值的空指针)。*/

InBlock.gif                        printf( "查询未返回结果集\n");
InBlock.gif                        printf( "错误编号:%d\n", mysql_errno(&mysql));
InBlock.gif                        printf( "错误信息:%s\n", mysql_error(&mysql));
InBlock.gif                        printf( "行数:%d\n", mysql_field_count(&mysql));
InBlock.gif                }
InBlock.gif                 else
InBlock.gif                {
InBlock.gif                        printf( "结果集的行数:%d\n", mysql_num_rows(res));
InBlock.gif                        MYSQL_ROW mr;
InBlock.gif                        MYSQL_FIELD *mf = mysql_fetch_fields(res);
InBlock.gif                         while((mr = mysql_fetch_row(res)) != NULL)
InBlock.gif                        {
InBlock.gif                                unsigned long *lengths;
InBlock.gif                                lengths = mysql_fetch_lengths(res);
InBlock.gif                                 for(unsigned int i = 0; i < mysql_num_fields(res); i++)
InBlock.gif                                {
InBlock.gif                                        printf( "%s:%s ", mf[i].name, mr[i]?mr[i]: "NULL");
InBlock.gif                                }
InBlock.gif                                printf( "\n");
InBlock.gif                        }
InBlock.gif
                }
InBlock.gif                mysql_free_result(res);
InBlock.gif        }
InBlock.gif         else
InBlock.gif        {
InBlock.gif                 int i = mysql_errno(&mysql);
InBlock.gif                printf( "发生错误:%s\n", mysql_error(&mysql));
InBlock.gif        }
InBlock.gif        mysql_close(&mysql);
InBlock.gif         return 0;
InBlock.gif}