Libzdb 实现了一个小型、快速和易用的线程安全的连接池数据库API,可连接多种数据库,零配置,通过URL指定连接信息。
Example: 默认建立5个连接
URL_T url = URL_new("mysql://localhost/test?user=root&password=swordfish");
ConnectionPool_T pool = ConnectionPool_new(url);
ConnectionPool_start(pool);
[..]
Connection_T con = ConnectionPool_getConnection(pool);
ResultSet_T result = Connection_executeQuery(con, "select id, name, image from employee where salary>%d", anumber);
while (ResultSet_next(result))
{
int id = ResultSet_getInt(result, 1);
const char *name = ResultSet_getString(result, 2);
int blobSize;
const void *image = ResultSet_getBlob(result, 3, &blobSize);
[..]
}
Connection_close(con);
[..]
ConnectionPool_free(&pool);
URL_free(&url);