+ -
当前位置:首页 → 问答吧 → 连接多个数据库的问题

连接多个数据库的问题

时间:2011-11-30

来源:互联网

我的应用大部分是连mysql数据库的,现在需要连接到oralce数据库查询部分数据,我定义了一个model连接oracle的表:
<?php
class TestLogModel extends AdvModel{

/* 数据库设置 */

protected $connection = array(

'dbms' => 'oracle',

'username' => 'test',

'password' => 'test',

'hostname' => '127.0.0.1',

'hostport' => '1521',

'database' => 'TEST',

);


}
?>

在action中单独访问是正常的:
$TestLog = D('TestLog');
$list=$TestLog->limit(4)->select();
dump($list);

但是如果action中在$TestLog = D('TestLog');之前连过mysql的数据库就会有问题;例如:
$Aaa = M('Aaa');
$listaaa=$Aaa->find();

$TestLog = D('TestLog');
$list=$TestLog->limit(4)->select();
dump($list);


这样就取不到数据,【$Aaa = M('Aaa');连接的是mysql数据库,测过没有问题, 可以正常取数据。】

如果把$TestLog = D('TestLog');放到$Aaa = M('Aaa');的前面,就可以正常取到数据。

有谁遇到这种情况吗?谁能帮我解决下。。。万分感谢!

作者: 21to5   发布时间: 2011-11-30

用getlastsql方法调试下最后执行的sql语句查下原因

作者: thinkphp   发布时间: 2011-11-30

$Aaa = M('Aaa');
$listaaa=$Aaa->find();

$TestLog = D('TestLog');
$list=$TestLog->limit(4)->select();
dump($list);

这个情况下getlastsql的结果如下:
bool(false)

SELECT * FROM `test_log` LIMIT 4

好像没有连接到oracle,而是到mysql中查找的【把limit(4)去掉也取不到数据】

作者: 21to5   发布时间: 2011-11-30