title: Connect PDO with Oracle database
body: <p>I am new to Oracle, installed the Oracle today the 11g Express Edition.
  Then I installed Java SDK, and then the free Oracle SQL Developer.
  I connected with system account and created a username and table as defined below. I don't exactly know how Oracle works, I think instead of database name, usernames are used. So below are details.</p>
  
  <p>Username/Connection/Database = <code>CustomSearch</code><br>
  Table = <code>Reservation_General_2</code></p>
  
  <p>There are some columns inside that table and some data. but the point is I cant connect to Oracle Server.</p>
  
  <p>Here is how I tried to connect to database server.</p>
  
  <pre><code>&lt;?php
  /**
   * Created by PhpStorm.
   * User: HaiderHassan
   * Date: 9/3/14
   * Time: 9:52 PM
   */
  header('Access-Control-Allow-Origin: *');
  $tns = "
  (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      )
      (CONNECT_DATA =
        (SERVICE_NAME = orcl)
      )
    )
         ";
  try {
      $conn = new PDO("oci:dbname=".$tns, 'customsearch', 'babaji');
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch(PDOException $e) {
      echo 'ERROR: ' . $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>Problem is when I try to open that page, I get this error.</p>
  
  <blockquote>
    <p>ERROR: could not find driver</p>
  </blockquote>
  
  <p>These are my connection settings when I connect from <code>Oracle Sql Developer</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/TwmQl.jpg" alt="enter image description here"></p>
  
  <p>What am I doing wrong, what steps should I take to fix this issue?</p>
  
  <h2>Update</h2>
  
  <p>I added the driver by removing semicolon from the <code>php.ini</code> file </p>
  
  <pre><code>extension=php_pdo_oci.dll 
  </code></pre>
  
  <p>But I started getting this error.</p>
  
  <blockquote>
    <p>The program can't start because OCI.dll is missing from your computer. Try reinstalling the program to fix this problem.</p>
  </blockquote>
  
  <p>I have to click 4 time OK for different alert boxes that shows up. I also downloaded <code>oci.dll</code> and copied it to the <code>windows/system32</code>, but still getting this error. What to do?</p>
  
  <h2>Update</h2>
  
  <p>I uninstalled XAMPP and followed this guide to install Apache and PHP separately,</p>
  
  <pre><code>http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html
  </code></pre>
  
  <p>and then I tried my luck. That driver Problem went away but there is new problem</p>
  
  <blockquote>
    <p>ERROR: SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12521: TNS:listener does not currently know of instance requested in connect descriptor (ext\pdo_oci\oci_driver.c:635)</p>
  </blockquote>
  
  <p>Here below is my new connection String.</p>
  
  <pre><code>try {
      $conn = new PDO('oci:dbname=//localhost:1521/xe/ORCL', 'customsearch', 'babaji');
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch(PDOException $e) {
      echo 'ERROR: ' . $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>I tried to follow this answer on Stack Overflow for making a connection string.</p>
  
  <pre><code>http://stackoverflow.com/questions/11970261/connect-oracle-with-pdo-with-sid-and-instance-name
  </code></pre>
  
  <h2>Update 2</h2>
  
  <p>Also tried to check if drivers installed. I used this code</p>
  
  <pre><code>foreach(PDO::getAvailableDrivers() as $driver)
      echo $driver, '\n';
  </code></pre>
  
  <p>Got this code from this below link</p>
  
  <pre><code>http://stackoverflow.com/questions/23239433/could-not-connect-to-oracle-using-pdo
  </code></pre>
  
  <p>it echoes this below line</p>
  
  <pre><code>oci\n
  </code></pre>
  
  <p>So this means that it is installed or this means some drivers are missing?</p>
  
  <h2>Update 3</h2>
  
  <p>Again rolled back to old connection just changed some stuff in that connection and seems like connection to oracle worked.</p>
  
  <pre><code>try {
      $conn = new PDO("oci:dbname=".$tns, 'customsearch', 'babaji');
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      echo 'Connected to database';
  } catch(PDOException $e) {
      echo 'ERROR: ' . $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>with this I get the message 'Connected to database', means echo works because there is no error given by PDO.</p>
  
  <p>But problem is now my query is not working? What happened to my query? Or will I have to change the syntax of the query also as I connected to Oracle? Or is the connection still not working?</p>