$db_hoorayos_config = array(
'dsn'=>'mysql:host=localhost;dbname=hoorayos',
'name'=>'root',
'password'=>'hooray'
);
$db = new HRDB($db_hoorayos_config);
$db_hoorayos_config2 = array(
'dsn'=>'mysql:host=localhost;dbname=hoorayos2',
'name'=>'root',
'password'=>'hooray'
);
$db2 = new HRDB($db_hoorayos_config2);
这样就能同时创建2个数据库连接,方便处理数据库与数据库交互的情况。
大致新功能就是这么多了,整个代码并不多,欢迎阅读了解。下面是我在编写时写的测试代码,也一并提供上来,方便大家学习。
复制代码 代码如下:
require_once('global.php');
require_once('inc/setting.inc.php');
$db = new HRDB($db_hoorayos_config);
echo '<hr><b>select测试</b><hr>';
echo '普通模式,直接字符串传入<br>';
$rs = $db->select(1, 0, 'tb_member', 'username, password', 'and type = 1 and username like "%os%"');
echo '<br>数组模式,可传入数组<br>';
$fields = array('username', 'password');
$where = array('type = 1', 'username like "%os%"');
$rs = $db->select(1, 0, 'tb_member', $fields, $where);
echo '<hr><b>insert测试</b><hr>';
echo '普通模式,直接字符串传入<br>';
$db->insert(1, 0, 'tb_member', 'username = "test", type = 1, lastlogindt = now()');
echo '<br>数组模式,可传入数组<br>';
$set = array('username = "test"', 'type = 1', 'lastlogindt = now()');
$db->insert(1, 0, 'tb_member', $set);
echo '<hr><b>update测试</b><hr>';
echo '普通模式,直接字符串传入<br>';
$db->update(1, 0, 'tb_member', 'username = "123", type = 1, lastlogindt = now()', 'and tbid = 7');
echo '<br>数组模式,可传入数组<br>';
$set = array('username = "123"', 'type = 1', 'lastlogindt = now()');
$where = array('tbid = 1');
$db->update(1, 0, 'tb_member', $set, $where);
echo '<hr><b>delete测试</b><hr>';
echo '普通模式,直接字符串传入<br>';
$db->delete(1, 0, 'tb_member', 'and tbid = 1 and username = "hooray"');
echo '<br>数组模式,可传入数组<br>';
$where = array(
'tbid = 1',
'username = "hooray"'
);
$db->delete(1, 0, 'tb_member', $where);
echo '<hr><b>自定义sql</b><hr>';
$db->query('select username, password from tb_member');
$rs = $db->fetchAll();
var_dump($rs);
$db->close();