本地XAMPP安装连接到live oracle DB DSN

时间:2015-11-25 18:34:42

标签: php oracle11g yii2

我在我的电脑上本地使用Yii2,但是希望连接到我们的生产服务器DB我尝试过字符串:

'dbname=//host:port/servicename',但它说Connection不支持阅读架构

我从未尝试过将Yii2连接到oracle或连接到实时数据库。如果可能的话,实现这个目标的方法是什么?

我也阅读了此链接https://www.quora.com/How-do-I-connect-Yii-to-Oracle 并将我改为所提及的格式

 'db' => [ 
  'class' => '\yii\db\Connection',
  'dsn' => 'oci:dbname=SOME_IP_ADDRESS:PORT/YOUR_SID;charset=UTF8',
  'username' => 'your_username',
  'password' => 'your_password',
  'charset' => 'utf8',
], 

但我得到了同样的错误。除了我使用服务名称代替SID

更新

好的,看看Yii代码

/**
 * Returns the schema information for the database opened by this connection.
 * @return Schema the schema information for the database opened by this connection.
 * @throws NotSupportedException if there is no support for the current driver type
 */
public function getSchema()
{
    if ($this->_schema !== null) {
        return $this->_schema;
    } else {
        $driver = $this->getDriverName();
        if (isset($this->schemaMap[$driver])) {
            $this->_schema = \Yii::createObject($this->schemaMap[$driver]);
            $this->_schema->db = $this;
            return $this->_schema;
        } else {
            throw new NotSupportedException("Connection does not support reading schema information for '$driver' DBMS.");
        }
    }
}

我认为不支持驱动程序,所以如何找出哪些驱动程序?

2 个答案:

答案 0 :(得分:1)

您需要安装并启用对Oracle数据库的PHP支持。

有详细的教程here

答案 1 :(得分:1)

经过一番搜索我的设置。以下为我工作

<强>配置/ db.php中

return [
'class' => 'yii\db\Connection',
'dsn' => 'oci:dbname=IP_ADDRESS:PORT/DB_NAME', 
'username' => 'USERNAME',
'password' => 'PASSWORD',
'charset' => 'utf8',
];

我还必须在我的php.ini文件中取消注释

extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client

我还必须从PECL http://pecl.php.net/package/oci8/2.0.8/windows/

下载OCI8 DLL驱动程序

我的XAMPP带有12c,但是我的设置无效。

相关问题