I have these snippets but I still cannot connect to my Oracle DB. I believe I did everything right but i don't know where the pitfall is.
try {
$user='weltesadmin'; // Enter your DB User Name.
$pass='weltespass'; // Enter your DB Password.
$dataBaseName='weltes'; // Enter your Database Name.
$dbh = new PDO('OCI:dbname='.$dataBaseName.'charset=UTF-8', $user,$pass);
echo "Connection Successful";
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . " ";
die();
}
And on the php.ini
:
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pdo_sqlite_external.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
Check your installed drivers and see if oci
is installed:
foreach(PDO::getAvailableDrivers() as $driver)
echo $driver, '
';
If oci
don't shown, then need to install it (http://php.net/manual/en/ref.pdo-oci.php)
My problem solved by following instructions on http://lacot.org/blog/2009/11/03/ubuntu-php5-oci8-and-pdo_oci-the-perfect-install.html
Do not forget to export oracle home .Even though oracle home was set i was not able to configure pdo_oci. So give export ORACLE_HOME=/opt/instantclient_10_2/ before running configure in pdo_oci-1.0 directory
adding this to requirements.php
array(
'name' => 'PDO Oracle extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_oci'),
'by' => 'All DB-related classes',
'memo' => 'Required for Oracle database.',
),
editing dsn in db.php as follows
return [
'class' => 'yii\db\Connection',
'dsn'=> 'oci:dbname=(DESCRIPTION=(ADDRESS=(HOST=x.y.z.a)(PROTOCOL=tcp)(PORT=1525))(CONNECT_DATA=(SID=YOURSID)))',
'username' => 'USER',
'password' => 'PASS',
'charset' => 'utf8',
];
Looking at the line:
$dbh = new PDO('OCI:dbname='.$dataBaseName.'charset=UTF-8', $user,$pass);
You have used OCI in caps replace that with "oci" (small case)
(A mistake I had made myself)
Once you change that uncommenting below line from php.ini is sufficient:
extension=php_pdo_oci.dll