---
title: "C语言数据库连接池 libzdb"
author: "zhanjun"
date: "2011-10-31T09:27:14Z"
tags: []
categories: ["编程语言"]
slug: "c-libzdb"
draft: false
lastmod: "2011-10-31T09:27:14Z"
id: 1223899
url: "https://zhanjun.iteye.com/blog/1223899"
---

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);
```