#include <mysql.h>
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
MYSQL *conn,mysql;
conn = mysql_init(&mysql);
if (conn==NULL) {
printf("mysql初始化失败!!!");
return -1;
}
conn = mysql_real_connect(&mysql, "127.0.0.1", "root","password", "test", 3306, NULL, 0);
if (conn) {
printf("连接成功\n");
}else{
printf("连接失败\n");
return -2;
}
char query[] = "select * from stu where snum = 001";
if (mysql_query(conn, query)){
printf("error_query\n");
}else{
MYSQL_RES *result;
MYSQL_ROW row;
result = mysql_store_result(conn);
while(row = mysql_fetch_row(result)){
printf("%s\t%s\n", row[0], row[1]);
}
}
mysql_close(conn);
return 0;
}
|