C连接Mysql

#include <windows.h>
#include <mysql.h>
#include "stdio.h"

#pragma comment(lib,"libmySQL.lib")

int main()
{
    MYSQL mysql;
    mysql_init(&mysql);
    mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"yangyh");
    if(!mysql_real_connect(&mysql,"localhost","root","root","9099",MYSQL_PORT,NULL,0)){
        fprintf(stderr,"Failed to connect to database: Error: %s\n",mysql_error(&mysql));
        //printf("error\n");
    }else printf("success\n");

    return 1;
}

posted on 2010-01-27 12:40  yangyh  阅读(205)  评论(0编辑  收藏  举报