Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test for an Oracle connection

I'm trying to connect to an Oracle DB which is currently offline. When it's online it's not a problem, however, now that it's offline my program is getting hung up on the $connection = oci_connect() line and timing out. How do I simply check the connectio and bail out if it's not there?

like image 612
user39653 Avatar asked Jan 26 '26 02:01

user39653


2 Answers

Try this (fill in your ip and port):

if ( @fsockopen($db_ip,$db_port ) ) {
    //connect to database
} else {
    // didn't work
}
like image 60
Jack Avatar answered Jan 27 '26 16:01

Jack


This gives you both a manual error, plus will return the actual error.

$connection = oci_connect() or die("Critical Error: Could not connect to database.\n\n". oci_error());

Make sure to test this as hopefully the Oracle error doesn't do something stupid like return the connection string (with your DB password) but I wouldn't assume until you see for yourself.

like image 23
TravisO Avatar answered Jan 27 '26 16:01

TravisO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!