Ich möchte meinen Raspberry Pi 2 mit Hilfe von C++ mit einer externen MySQL-Datenbank auf 000webhost.com verbinden.Verbinden des Raspberry Pi 2 mit einer externen Remote-Datenbank
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("<000webhost mysql address>", "<username>", "<password>");
/* Connect to the MySQL test database */
con->setSchema("<database>");
stmt = con->createStatement();
res = stmt->executeQuery("<sql statement>"); // replace with your statement
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column fata by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << ")" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
Ich habe eine Fehlermeldung, dass die mysql_connection.h
Datei fehlt. Ich weiß nicht, was ich falsch gemacht habe oder ob es einen leichteren oder einfacheren Weg gibt. Bitte helfen Sie mir bei dieser Angelegenheit. Vielen Dank.
Haben Sie die [Quelle installiert] (https: //dev.mysql.com/doc/connector-cpp/en/connector-cpp-installation-source.html), damit mysql_connection.h auf Ihrem Raspberry Pi funktioniert? – NonCreature0714
Ich habe mysql nicht auf dem Raspberry Pi installiert, seit ich versucht habe, auf eine externe Datenbank zuzugreifen. Ich bin neu in der Raspberry Pi-Umgebung. –
Beachten Sie, dass ich nicht gefragt habe, ob MySQL installiert ist, sondern die Quelle für die MySQL-Connector-C++ - Bibliothek, die nicht MySQL ist. Sie benötigen die Bibliothek, die dasselbe ist wie ein Paket in Python, aber für C++, damit mysql_connection.h funktioniert. – NonCreature0714