How to check connection with Oracle

I am trying to connect to an Oracle database that is currently disconnected. However, when it is online, this is not a problem, now that it is disconnected, my program gets stuck in the line $ connection = oci_connect () and the timeout. How can I just check the connection and release it if it does not exist?

+3
source share
4 answers

Try this (fill in your ip and port):

if ( @fsockopen($db_ip,$db_port ) ) {
    //connect to database
} else {
    // didn't work
}
+6
source

This gives you both a manual error and returns the actual error.

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

Be sure to check this out, as I hope the Oracle error doesn’t do something stupid, like returning the connection string (with your DB password), but I wouldn’t assume until you see for yourself.

+1

null .

, , , .

, , ​​ ?

You can use TNSPING to find out if the database is up ... ok, maybe it is not 100% accurate, but it is a good indicator. go to the command line and type TNSPING and press enter. So, you need to figure out how to call the command line tool from PHP.

0
source

Here is what I do in ASP.NET

Dim OracleConn As New OracleConnection(YOUR CONNECTION STRING HERE)
        Try
            OracleConn.Open()
            OracleConn.Close()
        Catch ex As Exception
            Session("ErrorMessage") = "OracleConn: " & ex.Message
            Response.Redirect("AccessDenied.aspx")
        End Try

He does not necessarily say that the database is offline, but an exception will occur if the connection does not open.

-2
source

All Articles