if(!mysql_real_connect(character_ptr,"localhost","root","24157518",
NULL
,0,NULL,0))
printf("Error
connecting
to
server:
%s\n",
mysql_error(character_ptr))
if(!mysql_select_db(character_ptr,
"test_database"))
printf("Error
connecting
to
database:
%s\n",
mysql_error(character_ptr))
帮你一下吧,我只能粗写,你自己详细参考一下函数库,下面localhost,是数据库服务器的地址,username,password分别为访问数据库所需要的用户名和密码,database是数据库的名称,请你参考MYSQL结构体以获取更加详细的参数信息
#include <stdlib.h>
#include<stdio.h>
#include "mysql.h"
int main(int argc,char**argv){
MYSQL *conn_ptr
conn_ptr=mysql_init(NULL)
if(!conn_ptr){
fprintf(stderr,"mysql_init failed\n")
return EXIT_FAILURE
}
conn_ptr=mysql_real_connect(conn_ptr,"localhost","username","password","database",0,NULL,0)
if(conn_ptr){
printf("Connection success\n")
}else{
printf("Connection failed\n")
}
mysql_close(conn_ptr)
return EXIT_SUCCESS
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)