- 解压缩 libopendbx1-mysql_1.2.3–1_i386.deb,会得到两个压缩包
- 解压缩 data.tar.gz,会得到一个文件夹名为 usr,进入到该文件夹中的 opendbx,将其拷贝到/usr/local/lib 下,并且把里面的共享库文件及连接文件拷贝到 /usr/lib 下
- 在 KDevelop 下 Target里面右键 选择 Options->libraries->link libraries ouside…内增加
-L
-lopendbx - 在CPP文件中增加 #include <odbx.h>
- 调用代码如下:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include <odbx.h>
using namespace std;
int main(int argc, char *argv[])
{
odbx_t* handle; //这个HANDLE是全局的,在 odbx_init()中初始化
int err = odbx_init( &handle, "mysql", "192.168.0.120", "3306");
int err1 = odbx_bind_simple(handle, "test", "test", "1234567");
//增删改查语句均可在这写
char qstr[] = "insert into test_table values ('z')";//"SELECT * FROM test_table";
char query[256];
int len = snprintf( query, 256, qstr);
int err5 = odbx_query( handle, query, len );
/*//获取查询返回值。使用方式要查看帮助。
//odbx_result()有两种,有返回值的调用odbx_result(),没有返回值的调用 odbx_result_free
odbx_result_t* result;
struct timeval tv = { 3, 0 };
int err6 = odbx_result( handle, &result, &tv, 0 );
int err7 = odbx_row_fetch(result);
*/
//完成事务并断开连接
odbx_finish(handle);
cout << "Init Connect to FireBird Server:" << err << odbx_error(handle, err) << "/r/n"
<< "Connect to a existing database file:" << err1 << odbx_error(handle, err1) << "/r/n"
<< "Start a query:" << err5 << odbx_error(handle, err5) << "/r/n"
//<< "Get the query result:" << err6 << odbx_error(handle, err6) << "/r/n"
//<< "odbx_row_fetch" << err7 << odbx_error(handle, err7) << "/r/n"
<< endl;
return EXIT_SUCCESS;
}