|
ADODB几乎成为了php数据库程序开发标准了,但是PearDB也已经进入了PHP的PECL库,如果你在为两者之间的选择二头疼的话,那大可不必了,ADODB已经提供了一部分向PearDB兼容的模式。
以下是笔者测试时候发现的,因为黄叶兄提供的空间PearDB居然无法工作,很奇怪的说
ADODB连接代码
[PHP]
<?php
//adodb connection
if($_CONFIG['db_driver'] == "adodb")
{
//connect to database
require_once("$ROOT_PATH/inc/adodb/adodb.inc.php");
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$DB =& ADONewConnection($_CONFIG['db_type']);
//connect to data base
switch ($_CONFIG['db_type'])
{
case "mysql":
case "mysqli":
$DB->Connect($_CONFIG['db_host'], $_CONFIG['db_username'], $_CONFIG['db_password'], $_CONFIG['db_name']);
break;
case "sqlite":
$DB->Connect("$ROOT_PATH/".$_CONFIG['db_name']);
break;
}
}
?>
[/PHP]
PearDB的连接代码
[PHP]
<?php
//pearDB connection
if($_CONFIG['db_driver'] == "pdb")
{
require_once("$ROOT_PATH/inc/pear/DB.php");
$dsn = array(
'phptype' => $_CONFIG['db_type'],
'username' => $_CONFIG['db_username'],
'password' => $_CONFIG['db_password'],
'hostspec' => $_CONFIG['db_host'],
'database' => $_CONFIG['db_name']);
if($_CONFIG['db_type'] == "sqlite")
{
$dsn = array(
'phptype' => $_CONFIG['db_type'],
'database' => "$ROOT_PATH/".$_CONFIG['db_name'],
'mode' => '0644');
}
$options = array(
'persistent' => $_CONFIG['pconnect'],
'debug' => $_CONFIG['debug']);
$DB =& DB::Connect($dsn, $options);
if (DB::isError($DB))
{
die($DB->getMessage());
}
$DB->setFetchMode(DB_FETCHMODE_ASSOC);
}
?>
[/PHP] |
|