#ifndef MYSQLCONN_H_
#define MYSQLCONN_H_
int TestMySQLConn();
#endif /* MYSQLCONN_H_ */
创建一个程序文件MySQLConn.c,代码如下:
/*
* MySQLConn.c
*
* Created on: Jun 11, 2009
* Author: zhanglei
*/
#include
#include
#include
#include
#include "MySQLConn.h"
int main(int agrc, char* argv[])
{
printf("MySQL Connection Test...");
return TestMySQLConn();
}
int TestMySQLConn()
{
MYSQL *pConn;
//MYSQL_RES *pRes;
//MYSQL_ROW my_conn;
pConn = mysql_init(NULL);
if(NULL == pConn)
{
printf("mysql_init failed!");
return EXIT_FAILURE;
}
pConn = mysql_real_connect(pConn, "127.0.0.1", "root", "123", "test", 3306, NULL, 0);
if(NULL == pConn)
{
printf("Connection failed!");
}
else
{
printf("Connection succeed!");
}
mysql_close(pConn);
return EXIT_SUCCESS;
}