标签:
#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; }
标签:
原文地址:http://www.cnblogs.com/leijiangtao/p/4623156.html