易截截图软件、单文件、免安装、纯绿色、仅160KB

linux c++连接mysql示例

 
 编译和连接程序
  MySQL中有一个特殊的脚本,叫做mysql_config. 它会为你编译MySQL客户端,并连接到MySQL服务器提供有用的信息.你需要使用下面两个选项.
  1. --libs 选项 - 连接MySQL客户端函数库所需要的库和选项.
  $ mysql_config --libs
  2. --cflags 选项 - 使用必要的include文件的选项等等.
  $ mysql_config --cflags
  你需要将上面两个选项加入到对源文件的编译命令中. 所以,要编译上面的程序,要使用下面的命令:
  $ g++ -o output-file $(mysql_config --cflags) test.c $(mysql_config --libs)
  执行编译后的程序:
  $ ./output.file
#include <mysql.h>
#include <stdlib.h>
#include <stdio.h>
static char *server_args[] =
{
"this_program", /* this string is not used */
"--datadir=.",
"--key_buffer_size=32M"
};
static char *server_groups[] =
{
"embedded",
"server",
"this_program_SERVER",
(char *)NULL
};
int main(void)
{
if (mysql_server_init(sizeof(server_args) / sizeof(char *),
server_args, server_groups))
exit(1);
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "admin";
char *password = "metrics"; /* 此处改成你的密码 */
char *database = "test";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables"))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
//utput table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);


相关文档:

Linux设备模型之input子系统详解

一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......

linux下file descriptoer限制


linux下file descriptoer限制
默认分类   2009-11-21 14:47   阅读0   评论0  
字号: 大大  中中  小小
Tuning file descriptor limits on Linux
Linux limits the number of file descriptors that any one process may open; the default limits are 1024 p ......

Linux下扩展硬盘

 
Linux下扩展硬盘(一)
(2009-09-26 19:15:12)
标签:it
 
四、fdisk 对硬盘及分区的操作,进入fdisk 对硬盘操作阶段
  我们可以对硬盘进行分区操作,前提是您把fdisk -l 弄明白了;通过fdisk -l
,我们能找出机器中所有硬盘个数及设备名称;比如上面的例子,我们会看到两个设备一个是/dev/hda ,另一 ......

Linux下无法mount本机IP的解决方法:

 设置dsn后虽然虚拟机可以上网了,但是用户名变成了bogon,而不是之前的localhost,去掉DNS后重启虚拟机就又变成了localhost
然后就可以mount本机了
还有一种方法:
hostname  显示当前主机名
hostname localhost 设置当前主机名为localhost
估计也可以解决上述不能mount的问题。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号