[MySQL] Problème mysql_query en C ++
Bonjour,
Alors voici mon code, tout compile parfaitement, quand j'éxécute, j'obtiens "OK" suivi de "KO" alors que c'est les même requête O_o ????
Quelqu'un peut m'aider ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #include <iostream>
#include "DataBase.h"
#include <winsock.h>
#include <MYSQL/mysql.h>
using namespace std;
int main()
{
MYSQL *con;
con = initialisation_DB();
if(mysql_query(con, "SELECT * FROM players") == 0)
cout << "OK" << endl;
else
cout << "KO" << endl;
if(mysql_query(con, "SELECT * FROM players") == 0)
cout << "OK" << endl;
else
cout << "KO" << endl;
close_DB(con);
delete con;
return 0;
} |
Voila DataBase.cpp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #ifndef DATABASE_H_INCLUDED
#define DATABASE_H_INCLUDED
#define IP_DB "localhost"
#define LOGIN_DB "***"
#define PASS_DB "***"
#define NAME_DB "***"
#include "DataBase.h"
#include <winsock.h>
#include <MYSQL/mysql.h>
#include <iostream>
using namespace std;
MYSQL *initialisation_DB()
{
MYSQL *mysql;
mysql = mysql_init(NULL);
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "option");
if(mysql_real_connect(mysql, IP_DB, LOGIN_DB, PASS_DB, NAME_DB, 0, NULL, 0) == NULL)
{
cout << "Erreur : Connexion DB impossible" << endl;
return NULL;
}
return mysql;
}
void close_DB(MYSQL *mysql)
{
mysql_close(mysql);
}
#endif // DATABASE_H_INCLUDED |
PS : Désolé si je ne suis pas dans la bonne rubrique pour poster ce post ^^'