- 初始化及连接成功
- 简单的sql语句执行
查询:
//查询
if (mysql_query(conn, "select * from newtable")){
print_error(conn, "mysql_query() error");
}
else{
MYSQL_RES *res_set;
res_set = mysql_store_result(conn); //生成结果集
if (res_set == NULL)
print_error(conn, "mysql_store_result failed");
else {
process_result_set(conn, res_set);
mysql_free_result(res_set);//记得释放
}
}
插入:
//插入
if (mysql_query(conn, "insert into newtable (id,name) values ('6','songshu')")){
print_error(conn, "执行插入失败");
}
else{
printf("插入成功,受影响行数:%lu\n", (ulong)mysql_affected_rows(conn));
}
更新:
//更新
<span style="white-space:pre"> </span>if (mysql_query(conn, "update newtable SET name= 'xiaosongshu 'WHERE `id` = 6 ")){
print_error(conn, "执行更新失败");
}
else{
printf("更新成功,受影响行数:%lu\n", (ulong)mysql_affected_rows(conn));
}
dbvisualizer sql语句自动提示设置: