Good day!
I am trying to connect to an Oracle database through PHP. When I try to connect via $ dbh = new PDO ($ dsn, $ user, $ password), an error is displayed:

pdo_oci_handle_factory: ORA-12154: TNS: I could not specify the identifier specified (ext \ pdo_oci \ oci_driver.c: 631) '

However, when I connect through the function oci_connect ($ user, $ password, $ shem), the connection works. Please help me figure out why this may be happening?
PS on the machine is Apache2.2 and php 5.4.0

  • The PDO documentation in the example suggests that php itself should indicate the entire block from tnsnames. php.net/manual/ru/ref.pdo-oci.php try as there. Or specify dbname equal to the name of the tnsnames section and nothing more - Mike
  • I tried it anyway, it still doesn’t connect ((php php_pdo_oci.dll is connected, there are no errors in the logs, everything is written in the PATH ... - nita
  • can the value of dsn provide an approximate and then people are wondering what is your scheme there? what driver? - Naumov
  • dsn is defined like this: $ dsn = 'oci: dbname = base_name; charset = AL32UTF8' - nita

1 answer 1

What do you have in the $ dsn variable?

For example, I have a connection to the MySQL database (although it doesn’t matter which DBMS) through the PDO layer it looks like. in the following way:

class Db { public static function getConnection() { $host = 'localhost'; $dbname = 'DataBase'; $user = 'root'; $password = 'Passwword'; $charsetByDefault = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password, $charsetByDefault); return $db; } } 

And everything, of course, works.

  • I construct the $ dsn variable in the following way: $ dsn = 'oci: dbname = NameBase; host = IP_Server_With_DB; charset = AL32UTF8' Of course, I take all the data from tnsnames.ora for oci_connect ($ user, $ password, $ shem), $ shem variable = 'IP_Server_With_DB / NameBase' - nita
  • But the PDO object is still not created ( - nita
  • 3
    That's just MySQL or oracle is very important. In an oracle with a connection, everything is different from other databases, so the answer based on MySQL is not correct. Many connection facilities require tnsnames.ora entries. - Mike
  • There is an entry in tnsname.ora, I can connect to the database via TOAD, but I can't get through the PDO object - nita