Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL C++连接器[ mySQL连接器-c++-0.0.19-LIUX-GLYBC2.2.x8664位]_C++_Mysql - Fatal编程技术网

MySQL C++连接器[ mySQL连接器-c++-0.0.19-LIUX-GLYBC2.2.x8664位]

MySQL C++连接器[ mySQL连接器-c++-0.0.19-LIUX-GLYBC2.2.x8664位],c++,mysql,C++,Mysql,我的应用程序崩溃: 调试时: #0 __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:371 #1 0x00007ffff7301c80 in std::string::append(std::string const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #2 0x00007ffff

我的应用程序崩溃:

调试时:

#0  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:371
#1  0x00007ffff7301c80 in std::string::append(std::string const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x00007ffff7634efe in sql::SQLString::append (str=..., this=0x7fffffffdc10)
    at /export/home/pb2/build/sb_0-32258110-1547655664.03/mysql-connector-c++-1.1.12/cppconn/sqlstring.h:155
#3  sql::mysql::MySQL_Connection::setSchema (this=0x55555578bed0, catalog=...)
    at /export/home/pb2/build/sb_0-32258110-1547655664.03/mysql-connector-c++-1.1.12/driver/mysql_connection.cpp:1345
#4  0x000055555555585d in main () at ../Crebaco/main.cpp:25

来自GDB的调用堆栈,我在使用mysql-connector-c++-1.1.12时遇到了相同的错误。代码非常简单。这不是答案,您可以尝试使用此代码连接到您的mysql实例吗

//export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/asif/Desktop/QT/Crebaco/mysql-connector-c++-8.0.19-linux-glibc2.12-x86-64bit/lib64

#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

using namespace std;

#define SERVERSTRING "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "password"
#define DATABASE "test"

int main()
{
    cout<<"Content-Type: application/txt\r\n\r\n";

    try {
      static sql::Driver *driver=get_driver_instance();
      shared_ptr<sql::Connection> con(driver->connect("127.0.0.1:3306","asif", "password"));
      con->setSchema("asif");

      shared_ptr<sql::Statement> stmt(con->createStatement());
      shared_ptr<sql::ResultSet> res(stmt->executeQuery("select * from tab1"));

      while (res->next()) {
          cout << res->getString("name") << endl;
      }

    }catch(sql::SQLException &e)
    {
        cout << "# ERR: " << e.what()<<endl;
        cout << "MySQL error code: " << e.getErrorCode()<<endl;
          //cout << ", SQLState: " << e.getSQLState()<<endl;
    }

    return 0;
}

您很可能无法连接到数据库。检查用户名、密码等。您好,我已经连接到数据库,condriver->connect127.0.0.1:3306,asif,password;通过,当我调用setschema时失败。如果我输入了错误的密码,它会正确地告诉我。调试器会怎么说?con看起来怎么样?例如,您可以获得一个segv,以防con为空。我检查了它,它不是空的,我已重新发送post以将堆栈展开。
#0  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:371
#1  0x00007ffff7301c80 in std::string::append(std::string const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x00007ffff7634efe in sql::SQLString::append (str=..., this=0x7fffffffdc10)
    at /export/home/pb2/build/sb_0-32258110-1547655664.03/mysql-connector-c++-1.1.12/cppconn/sqlstring.h:155
#3  sql::mysql::MySQL_Connection::setSchema (this=0x55555578bed0, catalog=...)
    at /export/home/pb2/build/sb_0-32258110-1547655664.03/mysql-connector-c++-1.1.12/driver/mysql_connection.cpp:1345
#4  0x000055555555585d in main () at ../Crebaco/main.cpp:25
//export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/asif/Desktop/QT/Crebaco/mysql-connector-c++-8.0.19-linux-glibc2.12-x86-64bit/lib64

#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

using namespace std;

#define SERVERSTRING "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "password"
#define DATABASE "test"

int main()
{
    cout<<"Content-Type: application/txt\r\n\r\n";

    try {
      static sql::Driver *driver=get_driver_instance();
      shared_ptr<sql::Connection> con(driver->connect("127.0.0.1:3306","asif", "password"));
      con->setSchema("asif");

      shared_ptr<sql::Statement> stmt(con->createStatement());
      shared_ptr<sql::ResultSet> res(stmt->executeQuery("select * from tab1"));

      while (res->next()) {
          cout << res->getString("name") << endl;
      }

    }catch(sql::SQLException &e)
    {
        cout << "# ERR: " << e.what()<<endl;
        cout << "MySQL error code: " << e.getErrorCode()<<endl;
          //cout << ", SQLState: " << e.getSQLState()<<endl;
    }

    return 0;
}