码迷,mamicode.com
首页 > 数据库 > 详细

linux-c语言连接mysql

时间:2015-07-05 23:52:38      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:


#include <mysql/mysql.h> #include <stdio.h> #include<stdlib.h> int main() { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *server = "localhost"; char *user = "root"; char *password = "123456"; char *database = "student"; conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } /* send SQL query */ if (mysql_query(conn, "SELECT * FROM info where sno=‘3‘")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } res = mysql_use_result(conn); /* output fields 1 and 2 of each row */ while ((row = mysql_fetch_row(res)) != NULL) printf("%s %s\n", row[0], row[1]); mysql_close(conn); return 0; }
技术分享

 

linux-c语言连接mysql

标签:

原文地址:http://www.cnblogs.com/leijiangtao/p/4623156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!