gpt4 book ai didi

c++ - VS2013 c++ 连接 mysql --- Libmysql.dll 中的错误

转载 作者:行者123 更新时间:2023-11-28 05:54:21 25 4
gpt4 key购买 nike

主要.cpp

#include "sqlConnection.h"
#include <iostream>
int main() {
sqlConnection *sqlC = new sqlConnection();
sqlC->ifSucceed();
}

sql连接.h

#include <Windows.h>
#include <stdio.h>
#include <winsock.h>
#include "mysql.h"
#include <iostream>
#pragma once

using namespace std;

class sqlConnection
{
public:
sqlConnection();
~sqlConnection();
void ifSucceed();
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
};

sql连接.cpp

#include "sqlConnection.h"

sqlConnection::sqlConnection()
{
mysql_init(&mysql);
mysql_real_connect(&mysql, "xxxxx", "xxxx", "xxxx", "librarySys", 7726, NULL, 0);
}

void sqlConnection::ifSucceed() {
char *sql = "select * from tb_bookcase";
mysql_query(&mysql, sql);
result = mysql_store_result(&mysql);
if ((row = mysql_fetch_row(result)) != NULL) {
cout << "succeed!" << endl;
} else {
cout << "faiiiiiiiiled" << endl;
}
}

sqlConnection::~sqlConnection() {
}

IF there is a libmysql.dll in source file error the message : There are untreated exception:0x00007FFED00441E6 (libmysql.dll) (in the librarySys.exe ) 0xC0000005: Access conflict happened when reading 0x0000000000000010.

然后我不得不停下来。 VS 给我选择,更改 PDB、二进制文件路径并重试。但我不知道该怎么做。

如果我删除 libmysql.dll ,错误信息是:

The program can not be started for losing libmysql.dll in the computer.Try to reinstall this program to solve this problem.

太乱了!我尝试了很多连接方式。总是有错误信息。

最佳答案

所有mysql_* 函数都返回一个指示成功或失败的值。您的代码忽略了它们。在进行下一个调用之前,您应该确认调用是否成功。我推测您实际上未能连接到数据库,并且您的 MYSQL 仍然无效。

使用调试器。在黑暗中编码毫无意义。使用您的调试器,您将快速查看您的 MYSQL 对象是否已正确初始化。

另一件事:

sqlConnection *sqlC = new sqlConnection();

没有理由将其分配到堆上。

关于c++ - VS2013 c++ 连接 mysql --- Libmysql.dll 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34539348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com