用codeblocks连接mysql问题
我想请问下用codeblocks连接mysql时要做些什么设置,是不是要添加什么include,lib文件夹。
我用的是mysqlserver6.0,驱动是mysqlodbc5.1,语言用的是c
已经试了很长时间就是不知道怎么设置,下面是连接的代码。请大家帮忙。谢谢
#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
int main()
{
MYSQL my_connection;
int res;
mysql_init(&my_connection);
if (mysql_real_connect(&my_connection, "localhost", "root", "123456","mysql",0,NULL,CLIENT_FOUND_ROWS))
{
printf("Connection success\n");
res = mysql_query(&my_connection, "insert into children values(10,'Ann',5)");
if (!res)
{
printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(&my_connection));
}
else
{
fprintf(stderr, "Insert error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
mysql_close(&my_connection);
}
else
{
fprintf(stderr, "Connection failed\n");
if (mysql_errno(&my_connection))
{
fprintf(stderr, "Connection error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
}
return 0;
}