1
<?php
echo "hello";

$db='(DESCRIPTION = ADDRESS = (PROTOCOL = TCP)(HOST = some_ip)(PORT = some_port))(CONNECT_DATA = (SID = xxx.yyy)))';

$conn=oci_connect('user','pass','$db');

if (!$conn){
   echo "No connection";
}
else{
   echo "Connected!";
}
?>

I got the above code. It displays hello but anything else, and I don't know why, because even if the connection failed, it should display "No connection", shouldn't it?

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • That possibly means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further; it's impossible to code properly without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). – Álvaro González Mar 06 '14 at 09:51
  • add `$e = oci_error(); echo $e['message'];` right after `$conn =oci_connect('user', 'pass', $db);` (non-quoted!) – Elias Van Ootegem Mar 06 '14 at 09:54

1 Answers1

7

Variables under single quotes will not be parsed !

Change this

$conn=oci_connect('user','pass','$db');

to

$conn=oci_connect('user','pass',$db); //<--- Removed the single quotes around the variable!

As Alvaro G Vicario mentioned .. you need to enable the error reporting on your PHP code.

Add this on top of your code.

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

You need to enable the oci extension. Go to your PHP.ini and uncomment these lines by removing the semicolon before them , save the file and restart your webserver

;extension=php_oci8.dll      
;extension=php_oci8_11g.dll 
Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • anything changes. Still just "hello". –  Mar 06 '14 at 09:52
  • 1
    This information is correct but doesn't really answer the question. I suspect that OCI8 is not enabled but the OP has not enabled error reporting. – Álvaro González Mar 06 '14 at 09:52
  • `oci_error()` would be a welcome addition if you want to debug... IMO – Elias Van Ootegem Mar 06 '14 at 09:55
  • ok, it isn't detecting the oci_connect. `Fatal error: Call to undefined function oci_connect() in /var/www/html...` Is that a library that need to be installed? The problem arises because my boss wants me to install a web server without internet connection, so I hve to manually install all the packages ¬¬ –  Mar 06 '14 at 09:57
  • @yzT - Yes, you need to enable the OCI8 extension in PHP, but you also need to install and configure (if you haven't already) the Oracle Instant Client or a similar library from the Oracle site. – Álvaro González Mar 06 '14 at 10:01
  • 1
    @ÁlvaroG.Vicario definitely I'll need to do that, because I don't have any match for "oci" on php.ini. It seems the question is answered already, just need to set things up correctly. –  Mar 06 '14 at 10:05