//MYSQL数据库操作模块类
#include
MYSQL mydb;
MYSQL_RES *res;
MYSQL_ROW myrow;
void *mysqlDllHandler;//mysql dll句柄
const char *dllError;//dll错误信息
char *sysMsg;//系统信息
//MYSQL接口函数
//数据库连接
MYSQL *(*mysqlConnect)(MYSQL *mysql, const char *host,
const char *user,
const char *passwd,
const char *db,
unsigned int port,
const char *unix_socket,
unsigned int clientflag);
//数据库查询
int (*mysqlQuery)(MYSQL *mysql, const char *q);
//结果数
my_ulonglong (*mysqlNumRows)(MYSQL_RES *res);
//数据结果集
MYSQL_RES *(*mysqlStoreResult)(MYSQL *mysql);
//单条结果
MYSQL_ROW (*mysqlFetchRow)(MYSQL_RES *result);
//关闭数据库、释放内存空间
void (*mysqlFreeResult)(MYSQL_RES *result);
//打开mysql动态共享库,并进行初始模块
void initMysql()
{
mysqlDllHandler=dlopen("/data1/webshop/www/cgi-bin/app/bbs/libmysqlclient.cdll",RTLD_LAZY);//打开mysql动态共享库
if(!mysqlDllHandler)
{
sysMsg="Open libmysqlclient.cdll file failed!";
sysInternalError(sysMsg);
}
//打开外部接口函数
mysqlConnect=(MYSQL *(*)(MYSQL *mysql, const char *host,
const char *user,
const char *passwd,
const char *db,
unsigned int port,
const char *unix_socket,
unsigned int clientflag))dlsym(mysqlDllHandler,"mysql_real_connect");
dllError=dlerror();
if(dllError)
{
sysMsg="Open libmysqlclient.cdll's function mysql_real_connect failed!";
sysInternalError(sysMsg);
}
mysqlQuery=(int (*)(MYSQL *mysql, const char *q))dlsym(mysqlDllHandler,"mysql_query");
dllError=dlerror();
if(dllError)
{
sysMsg="Open libmysqlclient.cdll's function mysql_query failed!";
sysInternalError(sysMsg);
}
mysqlNumRows=(my_ulonglong (*)(MYSQL_RES *res))dlsym(mysqlDllHandler,"mysql_num_rows");
dllError=dlerror();
if(dllError)
{
sysMsg="Open libmysqlclient.cdll's function mysql_num_rows failed!";
sysInternalError(sysMsg);
}
mysqlStoreResult=(MYSQL_RES *(*)(MYSQL *mysql))dlsym(mysqlDllHandler,"mysql_store_result");
dllError=dlerror();
if(dllError)
{
sysMsg="Open libmysqlclient.cdll's function mysql_store_result failed!";
sysInternalError(sysMsg);
}
mysqlFetchRow=(MYSQL_ROW (*)(MYSQL_RES *result))dlsym(mysqlDllHandler,"mysql_fetch_row");
dllError=dlerror();
if(dllError)
{
sysMsg="Open libmysqlclient.cdll's function mysql_fetch_row failed!";
sysInternalError(sysMsg);
}
mysqlFreeResult=(void (*)(MYSQL_RES *result))dlsym(mysqlDllHandler,"mysql_free_result");
dllError=dlerror();
if(dllError)
{
sysMsg="Open libmysqlclient.cdll's function mysql_free_result failed!";
sysInternalError(sysMsg);
}
}
作者: diudiu
发布时间: 2003-12-06