本文共 1021 字,大约阅读时间需要 3 分钟。
扩展PDO类可能是最好的选择.
class MyPDO extends PDO
{
protected $_table_prefix;
protected $_table_suffix;
public function __construct($dsn, $user = null, $password = null, $driver_options = array(), $prefix = null, $suffix = null)
{
$this->_table_prefix = $prefix;
$this->_table_suffix = $suffix;
parent::__construct($dsn, $user, $password, $driver_options);
}
public function exec($statement)
{
$statement = $this->_tablePrefixSuffix($statement);
return parent::exec($statement);
}
public function prepare($statement, $driver_options = array())
{
$statement = $this->_tablePrefixSuffix($statement);
return parent::prepare($statement, $driver_options);
}
public function query($statement)
{
$statement = $this->_tablePrefixSuffix($statement);
$args = func_get_args();
if (count($args) > 1) {
return call_user_func_array(array($this, 'parent::query'), $args);
} else {
return parent::query($statement);
}
}
protected function _tablePrefixSuffix($statement)
{
return sprintf($statement, $this->_table_prefix, $this->_table_suffix);
}
}
转载地址:https://blog.csdn.net/weixin_33239721/article/details/115158431 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!