用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4634|回复: 5
收起左侧

PDO连接非本地数据库服务器BUG

[复制链接]
发表于 2013-3-7 09:49:08 | 显示全部楼层 |阅读模式
本机IP192.168.1.1,使用PDO驱动连接192.168.1.2服务器的数据库BUG,始终连接到的是本机,请速度反馈
 楼主| 发表于 2013-3-7 09:50:54 | 显示全部楼层
使用原生的表示满意毫无压力

$db = new PDO('mysql:host=192.168.1.2;dbname=test;charset=UTF-8','root','123456');
$result=$db->query('show databases');
print_r($result->fetchAll());
发表于 2013-3-11 10:25:57 | 显示全部楼层
CI的PDO也是使用连接字符串连接的吧?
请把你的代码贴出来看一下,还有你的 CI 版本。
 楼主| 发表于 2013-3-17 13:20:44 | 显示全部楼层
本帖最后由 ziyan 于 2013-3-23 09:41 编辑

/*Default*/
$config['default']['hostname'] = 'mysql:host=localhost';
$config['default']['username'] = 'root';
$config['default']['password'] = '123456';
$config['default']['database'] = 'test';
$config['default']['dbdriver'] = 'pdo';
$config['default']['dbprefix'] = 'tbl_';
$config['default']['pconnect'] = false;
$config['default']['db_debug'] = true;
$config['default']['cache_on'] = false;
$config['default']['cachedir'] = '';
$config['default']['char_set'] = 'utf8';
$config['default']['dbcollat'] = 'utf8_general_ci';
$config['default']['swap_pre'] = '';
$config['default']['autoinit'] = false;
$config['default']['stricton'] = false;
$config['default']['port']     = 3306;

$config['write']['hostname'] = 'mysql:host=192.168.1.9';
$config['write']['username'] = 'root';
$config['write']['password'] = '123456';
$config['write']['database'] = 'discuz';
$config['write']['dbdriver'] = 'pdo';
$config['write']['dbprefix'] = 'pre_';
$config['write']['pconnect'] = false;
$config['write']['db_debug'] = true;
$config['write']['cache_on'] = false;
$config['write']['cachedir'] = '';
$config['write']['char_set'] = 'utf8';
$config['write']['dbcollat'] = 'utf8_general_ci';
$config['write']['swap_pre'] = '';
$config['write']['autoinit'] = false;
$config['write']['stricton'] = false;
$config['write']['port']     = 3306;

===========以上是自定义config/database.php============

====================扩展CI_Model==============
class MY_Model extends CI_Model {
        public function __construct(){
                parent::__construct();
                $this->load->config('database',true);
                $this->load->database($this->config->item('default','database'));
        }
}
?>


=========
连接$config['default']毫无问题,连$config['write']始终连接本机地址,用原生的PDO连接可以连局域网机器



 楼主| 发表于 2013-3-17 13:22:04 | 显示全部楼层
板本 CodeIgniter_2.1.3
 楼主| 发表于 2013-3-17 13:23:41 | 显示全部楼层
@hex 可以自己试一下,两台机器肯定可以试出来的

本版积分规则