#include
#include
#include
* 我只演示了连接,执行语句等请搜索网上例子
* 项目需要连接 libmysql.lib
* 执行程序需要包含 libmySQL.dll
*/
int main()
{
MYSQL * temp = NULL;
MYSQL * temp2 = NULL;
my_bool my_true = true; const char* hostname = "localhost"; //数据库地址
const char* usernmae = "root"; //用户名
const char* password = "root"; //密码
const char* dbName = "test"; //数据库名
unsigned int port = 3306; //端口 temp = mysql_init( NULL );
if(!temp)
{
printf("初始化失败");
return 0;
} if(mysql_options(temp, MYSQL_SET_CHARSET_NAME, "gbk"))
{
printf("设置charset失败");
return 0;
} if(mysql_options(temp, MYSQL_OPT_RECONNECT, &my_true))
{
printf("设置可重连失败");
return 0;
} temp2 = mysql_real_connect(temp, hostname, usernmae, password, dbName, port, NULL, 0);
if(!temp2)
{
printf("连接失败");
mysql_close(temp);
return 0;
} printf("连接成功,`temp2` 即为mysql连接,用做后续的查询等操作."); return 0;
}