易截截图软件、单文件、免安装、纯绿色、仅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,可以仔细的研究一下!)
键盘驱动将检 ......

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

C/C++——小编谈C语言函数那些事(20)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.     setallpallette函数
setallpallette函数的功能是按指定方式改变所有的调色板颜色,其用法为:void far setallpallette(struct palette, fa ......

Enable/Disable Linux mousekeys

 
gcc mousekey.c -lX11 -IX11
打开mousekeys运行./a.out
关闭mousekeys运行./a.out 1,这里在a.out后面随便加一个参数就可以了,因为判断条件为 if(argc < 2)
/*********source code***************/
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X ......

【转】linux socket()调用与arp报文发送

 Linux提供最常用的网络通信应用程序开发接口--Berkerley套接字(Socket).它既适用于同一主机上进程间通信(IPC),又适用于不同主机上的进程间通信。套接字的设置通过socket调用完成:
int socket(int family,int type,int protocol);
其中family指通信域或协议族,Linux系统支持的网络协议族有PF_UNIX,PF_IPX,PF_P ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号