Oracle and Yii2

How about friends someone can tell me how to connect oracle of yii2 with step by step,

The version oracle is 11g

use

‘db_o’ => [

‘class’ => ‘yii\db\Connection’,

‘connectionString’=>‘oci:dbname=//192.168.2.1:1521/ORCL;charset=UTF8’,

‘username’=>‘usuario’,

‘password’=>‘clave’,

],

I get this error

Unknown Property – yii\base\UnknownPropertyException

Setting unknown property: yii\db\Connection::dns




'db_o' => [

    'class' => 'yii\db\Connection',

    'dsn'=>'oci:dbname=//192.168.2.1:1521/ORCL;charset=UTF8',

    'username'=>'usuario',

    'password'=>'clave',

],




Hi, Thank for share code.

I used Yii1 with Oracle, but it was bad experience, the performance was very bad, hope you fix it in Yii2 :)

thanks

1 Like

and this code for SQL server: (extra info :) )


'db_o' => [

    'class' => 'yii\db\Connection',

    'dsn'=>'sqlsrv:Server=.\SQLEXPRESS;Database=DB_Name;charset=UTF8',

    'username'=>'usuario',

    'password'=>'clave',

],



change ‘connectionString’=>‘oci:dbname=//192.168.2.1:1521/ORCL;charset=UTF8’,

to ‘dsn’=>‘oci:dbname=//192.168.2.1:1521/ORCL;charset=UTF8’,

I get this error

Unknown Property – yii\base\UnknownPropertyException

Setting unknown property: yii\db\Connection::dns

dns → dsn.

I worked thanks

Hi guys. I can’t conect my Yii app with Oracle 12g, I got the error: could not find driver -> Caused by: PDOException -> could not find driver. I tried many way to connect it, but failed.

Follow my tries:


return [

    'components' => [

        'db' => [

            'class' => 'yii\db\Connection',

            //'dsn' => 'oci:dbname=//ip:port/sid;charset=UTF8',

            'dsn' => 'oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ip)(PORT=port))(CONNECT_DATA=(SID=sid)))',

            'username' => 'user',

            'password' => 'pwd',

            'charset' => 'utf8',

        ],

I don’t know what to do.

1 Like

have you it installed ?

manual

I Tried it @Pasman p, But not work. The oci_pdo.so is on /usr/lib64/php/modules/ in my php.ini I put extension = oci_pdo.so, reload the Apache service and nothing.

I know that oci_pdo.so library is experimental. There is an extension/Library that avoids this problem? Comparing with another framework there is a library that does this.

Or… Somebody can send me this damn oci_pdo.so librari to try again? My PHP is 5.5.20 - SO: Fedora 19

Having used the oci_pdo for over a year on yii 1.1, I really don’t recommend it.

There is a fair easier solution, instead of using oci_pdo, try using pdo_odbc then make a unixODBC connection to your Oracle instance, it’s way easier then making oci_pdo work.

You will have to tell Yii that your connection is an Oracle connection, otherwise it won’t work.

Also, if you’re using oracle on a different charset, but wants your oracle client to receive the data in utf-8, you’ll get a nasty error of buffer overflow. It’s fixable, but you’ll need to compile pdo_oci again, if you use pdo_odbc then you’re good.

@Rubens, do you have an example about it?

I think, that I need to install pdo_odbc I’ll get the same problem. I try to compile pdo_oci, I have it created on my dir, but when I try call it, its fail.

Other thing my environment is old, I use Fedora 19 yet.

I am also getting same error and using Windows.

It was ok with Yii 1.x as i used.

if anyone can resolve this please do inform. its very terrific error.

Tente isso:
no arquivo config/db.php

$dns = "
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = porta))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = servicename)
)
)";

return [
‘class’ => ‘yii\db\Connection’,
‘dsn’ => ‘oci:host=’.$dns.’;dbname=DB’,
// ‘dsn’ => $dns,
// ‘dsn’ => $dns,
‘username’ => ‘user’,
‘password’ => ‘pass’,
‘charset’ => ‘utf8’,

// Schema cache options (for production environment)
//‘enableSchemaCache’ => true,
//‘schemaCacheDuration’ => 60,
//‘schemaCache’ => ‘cache’,
];