Home > Database > Mysql Tutorial > body text

Linux下MySQL C++连接操作

WBOY
Release: 2016-06-07 16:58:20
Original
1159 people have browsed it

1,客户端需要安装mysql-client包,安装完后有我们需要的库文件;2,然后安装mysql-dev包,安装完后有我们需要的mysql.h文件;3,作

1,客户端需要安装mysql-client包,安装完后有我们需要的库文件;

2,然后安装mysql-dev包,安装完后有我们需要的mysql.h文件;

3,作为客户端只需要安装这两个包就可以了:

以下是简单的测试代码:
#include
#include
int   main()
{
/*declare   structures   and   variables   */
MYSQL   mysql;
MYSQL_RES   *result;
MYSQL_ROW   row;
//initialize   MYSQL   structure
mysql_init(&mysql);
//connect   to   database
//   mysql_real_connect(&mysql,"localhost","root","nriet","test",0,NULL,0);
mysql_real_connect(&mysql,"192.168.13.27","root","nriet","nriet",0,NULL,0);
//execute   query
mysql_query(&mysql,"select *   from   test");
//get   result   set
result=mysql_store_result(&mysql);
//process   result   set
while((row=mysql_fetch_row(result)))
{
fprintf(stdout,"%s   -   %s\n",row[0],row[1]);
}
//mysql_query(&mysql,"insert into test values(3,'a')");
//clean   up
mysql_free_result(result);
mysql_close(&mysql);
}

4,在“GCC C++ Linker”下的“Libraries”:

libraries(-l):mysqlclient
Libraries search path(-L):/usr/lib/mysql
然后 就可以 大功告成了 !!

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template