Hello world ! J’essaye depuis quelques jours de me connecter a ma base MySQL depuis un programme en c++ … mais apparemment, c’est pas si évident que ç’a l’air … Je bosse sur DEV C++ sous windoz, j’ai téléchargé le dernier package disponible de MySQL, placé le libmysql.dll dans mon répertoire et « linker » -lmysql coté compilation… seulement j’obtiens toujours l’erreur : //---------------------------------------------------------------------------------------------------- In file included from CDev-Cpp/include/MySQL/mysql.h:57, from mysqliostream.cpp:3: CDev-Cpp/include/MySQL/mysql_com.h:116: error: 'SOCKET' is used as a type, but is not defined as a type. CDev-Cpp/include/MySQL/mysql_com.h:180: error: `SOCKET' was not declared in this scope CDev-Cpp/include/MySQL/mysql_com.h:180: error: syntax error before `,' token make.exe: *** [mysqliostream.o] Error 1 //----------------------------------------------------------------------------------------------------
Marsh Posté le 07-02-2005 à 18:26:11
Hello world !
J’essaye depuis quelques jours de me connecter a ma base MySQL depuis un programme en c++ … mais apparemment, c’est pas si évident que ç’a l’air …
Je bosse sur DEV C++ sous windoz, j’ai téléchargé le dernier package disponible de MySQL, placé le libmysql.dll dans mon répertoire et « linker » -lmysql coté compilation… seulement j’obtiens toujours l’erreur :
//----------------------------------------------------------------------------------------------------
In file included from CDev-Cpp/include/MySQL/mysql.h:57,
from mysqliostream.cpp:3:
CDev-Cpp/include/MySQL/mysql_com.h:116:
error: 'SOCKET' is used as a type,
but is not defined as a type.
CDev-Cpp/include/MySQL/mysql_com.h:180:
error: `SOCKET' was not declared in this scope
CDev-Cpp/include/MySQL/mysql_com.h:180: error: syntax error before `,' token make.exe: *** [mysqliostream.o] Error 1
//----------------------------------------------------------------------------------------------------
voici mon programme:
#include <iostream>
#include <MySQL/mysql.h>
using namespace std;
int main()
{
MYSQL mysql;
mysql_init(&mysql);
char *v1;
int v2;
char *v3;
char *v4;
char *v5;
cout << "server"<<endl;
cin >> v1;
cout << "port"<<endl;
cin >> v2;
cout << "login"<<endl;
cin >> v3;
cout << "pass"<<endl;
cin >> v4;
cout << "base"<<endl;
cin >> v5;
if (!mysql_real_connect(&mysql,v1,v3,v4,v5,v2,NULL,0))
{
cout<<"erreur "<< mysql_error(&mysql)<<endl;
}
else{
char *sql;
sql= "create table test_cpp(id int);" ;
if (!mysql_query(&mysql,sql))
{
cout << mysql_error(&mysql)<<endl;
}
else
{
cout << "hello Mysql !"<<endl;
}
}
mysql_close(&mysql);
system("pause" );
return 0;
}