编写 insert.c
///////////////////////////////////
/* insert.c */
#include
#include
#include
/* 注意哦,上面写的是 mysql.h 的绝对地址,一般在/usr/include/mysql 下,仔细看看你的在哪里?这种方
式 #include "mysql/h" 可能也可以*/
int main(int argc, char *argv[])
{
MYSQL
my_connection;
int
res;
mysql_init(&my_connection);
/*mysql_real_connect(&mysql,主机名,用户名,密码,数据库名,0,NULL,0) ==
NULL)*/
/*mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) ==
NULL)*/
if
(mysql_real_connect(&my_connection,
"localhost",
"","cusemysql",0,NULL,CLIENT_FOUND_ROWS))
{
printf("Connection success");
res = mysql_query(&my_connection, "insert into children
values(11,'Anny',5)");
"root",
if (!res)
{
printf("Inserted %lu rows",(unsigned long)mysql_a?ected_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
评论0
最新资源