在DEV C++下,用C和MYSQL进行连接失败
运行显示processexitedwithreturnvalue3221225781pressantkeytocontinue......搞了好久,都不知道怎么回事,刚刚...
运行显示
process exited with return value 3221225781
press ant key to continue......
搞了好久,都不知道怎么回事,刚刚接触,完全小白,请各位高人指点。由于这是新号,没什么悬赏,不好意思,麻烦大家帮帮忙XD;
#include <winsock2.h>
#include <stdio.h>
#include<string.h>
#include <mysql.h>
#include<conio.h>
int main()
{
MYSQL mysql;
mysql_init(&mysql);
getch();
if(!mysql_real_connect(&mysql,"localhost","root","a445208178","library",0,NULL,0))
{
printf("Could not connect to MySQL server\n");
}
else
{
printf("Connection successful\n");
}
mysql_close(&mysql);
}
发现运行到mysql init时候就会出现这问题 展开
process exited with return value 3221225781
press ant key to continue......
搞了好久,都不知道怎么回事,刚刚接触,完全小白,请各位高人指点。由于这是新号,没什么悬赏,不好意思,麻烦大家帮帮忙XD;
#include <winsock2.h>
#include <stdio.h>
#include<string.h>
#include <mysql.h>
#include<conio.h>
int main()
{
MYSQL mysql;
mysql_init(&mysql);
getch();
if(!mysql_real_connect(&mysql,"localhost","root","a445208178","library",0,NULL,0))
{
printf("Could not connect to MySQL server\n");
}
else
{
printf("Connection successful\n");
}
mysql_close(&mysql);
}
发现运行到mysql init时候就会出现这问题 展开
2个回答
展开全部
给你个例子:
这个是DEV C++编译通过的
#include <windows.h>
#include <iostream>
#include <mysql/mysql.h>
#define SELECT_QUERY "select * from stu "
using namespace std;
int main(int argc, char *argv[])
{
//connection params
char *host = "localhost";
char *user = "root";
char *pass = "123";
char *db = "mydb";
//sock
MYSQL *sock;
MYSQL_RES *res;
sock = mysql_init(0);
if (sock) cout << "sock handle ok!" << endl;
else{
cout << "sock handle failed!" << endl;
return EXIT_FAILURE;
}
//connection
if (mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
cout << "connection ok!" << endl;
else{
cout << "connection failed!" << endl;
return EXIT_FAILURE;
}
//query
if (mysql_query (sock, SELECT_QUERY ))
{
cout << "Query failed " << mysql_error(sock) << endl;
exit(1);
}
if ( !( res = mysql_store_result( sock )))
{
cout << "Couldn't get result from " << mysql_error(sock) <<endl;
exit(1);
}
MYSQL_FIELD *field;
MYSQL_ROW row;
while ((field = mysql_fetch_field(res)))
{
printf("field name %s ", field->name);
}
while ( row = mysql_fetch_row ( res ))
{
cout<<row[0]<<" "<<row[1]<<endl;
}
system("PAUSE");
//closing connection
mysql_free_result ( res );
mysql_close(sock);
return EXIT_SUCCESS;
}
这个是DEV C++编译通过的
#include <windows.h>
#include <iostream>
#include <mysql/mysql.h>
#define SELECT_QUERY "select * from stu "
using namespace std;
int main(int argc, char *argv[])
{
//connection params
char *host = "localhost";
char *user = "root";
char *pass = "123";
char *db = "mydb";
//sock
MYSQL *sock;
MYSQL_RES *res;
sock = mysql_init(0);
if (sock) cout << "sock handle ok!" << endl;
else{
cout << "sock handle failed!" << endl;
return EXIT_FAILURE;
}
//connection
if (mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
cout << "connection ok!" << endl;
else{
cout << "connection failed!" << endl;
return EXIT_FAILURE;
}
//query
if (mysql_query (sock, SELECT_QUERY ))
{
cout << "Query failed " << mysql_error(sock) << endl;
exit(1);
}
if ( !( res = mysql_store_result( sock )))
{
cout << "Couldn't get result from " << mysql_error(sock) <<endl;
exit(1);
}
MYSQL_FIELD *field;
MYSQL_ROW row;
while ((field = mysql_fetch_field(res)))
{
printf("field name %s ", field->name);
}
while ( row = mysql_fetch_row ( res ))
{
cout<<row[0]<<" "<<row[1]<<endl;
}
system("PAUSE");
//closing connection
mysql_free_result ( res );
mysql_close(sock);
return EXIT_SUCCESS;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
需要代做吗?这个可以帮助你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询