Ajouter main.cpp
This commit is contained in:
38
main.cpp
Normal file
38
main.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <mysql_driver.h>
|
||||||
|
#include <mysql_connection.h>
|
||||||
|
#include <cppconn/driver.h>
|
||||||
|
#include <cppconn/statement.h>
|
||||||
|
#include <cppconn/resultset.h>
|
||||||
|
#include "User.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
try {
|
||||||
|
sql::mysql::MySQL_Driver *driver;
|
||||||
|
sql::Connection *con;
|
||||||
|
|
||||||
|
driver = sql::mysql::get_mysql_driver_instance();
|
||||||
|
// Connexion à XAMPP
|
||||||
|
con = driver->connect("tcp://127.0.0.1:3306", "root", "");
|
||||||
|
con->setSchema("university_db");
|
||||||
|
|
||||||
|
std::cout << "SUCCESS: Connexion etablie avec XAMPP !" << std::endl;
|
||||||
|
|
||||||
|
sql::Statement *stmt = con->createStatement();
|
||||||
|
sql::ResultSet *res = stmt->executeQuery("SELECT username FROM users");
|
||||||
|
|
||||||
|
while (res->next()) {
|
||||||
|
std::cout << "Utilisateur trouve dans la base : " << res->getString("username") << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete res;
|
||||||
|
delete stmt;
|
||||||
|
delete con;
|
||||||
|
|
||||||
|
} catch (sql::SQLException &e) {
|
||||||
|
std::cout << "ERREUR SQL : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user