yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

yii2 with oracle and gii error #15468

Closed PyPiMe closed 6 years ago

PyPiMe commented 6 years ago

I can connect remotely to DB with sqldeveloper. I can connect with sqlplus to DB.I can successfully run the following code and get the correct result

<?php
// demo.php
$username = 'user';
$password = 'pwd';

$connectText = '//remoteip:1521/test';

putenv("NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK");
$conn = oci_connect($username, $password, $connectText);
if (!$conn) {
    $e = oci_error();
    echo 'Oracle connect false<br />';
    exit($e['message']);
}

echo 'Oracle cnnectted';

// Prepare the statement
$stid = oci_parse($conn, "SELECT * FROM CODE_XSB");
if (!$stid) {
    $e = oci_error($conn);
    exit($e['message']);
}

// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);
    exit($e['message']);
}
// Fetch the results of the query
print "<table>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    print "<tr>\n";
    foreach ($row as $item) {
        $item = ($item !== null ? mb_convert_encoding($item, 'utf-8', 'gbk') : " ");
        print "    <td>" . $item . "</td>\n";
    }
    print "</tr>\n";
}
print "</table>\n";
oci_free_statement($stid);
oci_close($conn);

But I can't make gii to work.

main-local.php
'oracledb' => [
            'class' => 'yii\db\Connection',
            'dsn'=>'oci:dbname=//remoteip:1521/test;charset=utf8',
            'username'=>'user',
            'password'=>'pwd',

I got following error message:

Database Exception – yii\db\Exception
could not find driver
↵
Caused by: PDOException
could not find driver

in /home/www/devnet/Yii2/vendor/yiisoft/yii2/db/Connection.php at line 660
samdark commented 6 years ago

Means either you don't have PDO driver installed/enabled in php.ini or you're specifying DSN incorrectly.

yii-bot commented 6 years ago

Thank you for your question. In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

This is an automated comment, triggered by adding the label question.