rrors when i embed libmysqld in mysql APP on windows with VC7.1!!
Posted: Fri 10 Nov 2006 03:19
I make a test to embed libmyqld in my app with vc7.1,but there is something wrong!
What i do is below:
1. I create a win32 console project!
2. I create a cpp file named test_embed!The content with it is:
#include
#include
#include
#include "mysql.h"
MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;
static char *server_options[]={"mysql_test","--defaults-file=C:/my.ini"};
int num_elements=sizeof(server_options)/sizeof(char *);
static char *server_groups[]={"libmysqld_server", "libmysqld_client"};
int _tmain(int argc, _TCHAR* argv[])
{
std::cout<<"begin!"<<'\n';
if(!mysql_server_init(num_elements,server_options,server_groups))
std::cout<<"mysql_serve_init success!"<<'\n' ;
else
{
std::cout<<"mysql_serve_init fail!"<<'\n' ;
return 1 ;
}
mysql=mysql_init(NULL);
std::cout<<"mysql_init!"<<'\n' ;
mysql_options(mysql,MYSQL_READ_DEFAULT_GROUP,"libmysqld_client");
mysql_options(mysql,MYSQL_OPT_USE_EMBEDDED_CONNECTION,NULL);
mysql_real_connect(mysql,NULL,NULL,NULL,"mysql",3306,NULL,0);
mysql_query(mysql,"SELECT Host, User FROM user");
results=mysql_store_result(mysql);
while((record = mysql_fetch_row(results)))
std::cout<<record[0]<<","<<record[1]<<'\n' ;
mysql_free_result(results);
mysql_close(mysql);
mysql_server_end();
return 0;
}
3.the content of my.ini is:
# my.ini
[libmysqld_server]
datadir = C:/mysql/data/
language = C:/mysql/share/english/
skip-innodb
[libmysqld_client]
language = C:/mysql/share/english/
I have do the thing above!But the app always failed in mysql_server_init()!
Anybody can tell me why?
And the libmysqld.lib is added to dependencies!
the libmysqld.dll is in the dir with the test_embed.exe!
my Mysql version is 4.1.21!
What i do is below:
1. I create a win32 console project!
2. I create a cpp file named test_embed!The content with it is:
#include
#include
#include
#include "mysql.h"
MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;
static char *server_options[]={"mysql_test","--defaults-file=C:/my.ini"};
int num_elements=sizeof(server_options)/sizeof(char *);
static char *server_groups[]={"libmysqld_server", "libmysqld_client"};
int _tmain(int argc, _TCHAR* argv[])
{
std::cout<<"begin!"<<'\n';
if(!mysql_server_init(num_elements,server_options,server_groups))
std::cout<<"mysql_serve_init success!"<<'\n' ;
else
{
std::cout<<"mysql_serve_init fail!"<<'\n' ;
return 1 ;
}
mysql=mysql_init(NULL);
std::cout<<"mysql_init!"<<'\n' ;
mysql_options(mysql,MYSQL_READ_DEFAULT_GROUP,"libmysqld_client");
mysql_options(mysql,MYSQL_OPT_USE_EMBEDDED_CONNECTION,NULL);
mysql_real_connect(mysql,NULL,NULL,NULL,"mysql",3306,NULL,0);
mysql_query(mysql,"SELECT Host, User FROM user");
results=mysql_store_result(mysql);
while((record = mysql_fetch_row(results)))
std::cout<<record[0]<<","<<record[1]<<'\n' ;
mysql_free_result(results);
mysql_close(mysql);
mysql_server_end();
return 0;
}
3.the content of my.ini is:
# my.ini
[libmysqld_server]
datadir = C:/mysql/data/
language = C:/mysql/share/english/
skip-innodb
[libmysqld_client]
language = C:/mysql/share/english/
I have do the thing above!But the app always failed in mysql_server_init()!
Anybody can tell me why?
And the libmysqld.lib is added to dependencies!
the libmysqld.dll is in the dir with the test_embed.exe!
my Mysql version is 4.1.21!