Jump to content

Error during connection to DB2 database


patrickoq

Recommended Posts

Hi Guys, I wonder if you can help me. I am running some queries in DB2 database. To access that db I have to be connected through VPN, then it works fine. Of course when I am disconnected from VPN, don't have access to this db what is obvious. But I would like to handle this situation because obviously I am getting error that communication error has been detected. This is how I establish connection through PHP code:

 

$conn = odbc_connect('DSNname','user','password') or die("Error");

 

So, my expactation is when connection is not established then function returns 0 and text ERROR should show up. However, I am always getting error like below:

 

"Warning: odbc_connect() [function.odbc-connect]: SQL error: [iBM][CLI Driver] ......................"

 

Any idea how to handle it  ?, when my PC is not connnected to VPN  ? 

 

Thanks in advance.

Link to comment
Share on other sites

hi Patrick,

that error

"Warning: odbc_connect() [function.odbc-connect]: SQL error: [iBM][CLI Driver] ......................"

is critical. If you just want to output just ERROR, sometimes it's not sufficient to debug the error. And that error will always appear. And don't know if you know what that error means, it just that your odbc connection namely the DSNname is no longer exist because you don't have connection (that's obvious like you said). but here's the answer to your problem if you only want to display the text ERROR, do this,

$conn = @odbc_connect('DSNname','user','password') or die("Error");

the @will tell php to forget about its own built error message, and use whatever you gave it...

i think ;) It'll work try it

Link to comment
Share on other sites

  • 2 weeks later...

Hi IronMask, sorry for late reply, but was on vacation. This is what i was looking for, perfectly works. That "DIE("ERROR"), was just an example, of course in my code it's not handled like that :)

 

One more thing. Probably as you have noticed, I am not an advanced user, so forgive me that trivial question. But what exactly '@' means in this case ? 

Link to comment
Share on other sites

@ is simply used to suppress PHP messages.  Most comonly it is used for conditional existance checks (eg.  if(@$GET_['me']){...}), where PHP will fling up usassigned variable notices.  I don't suggest you suppress actual error messages though - log them someplace if you preffer, but don't suppress them.  That you were getting the error before your "or die" was being processed may point to an issue that should be addressed, not swept under the carpet.

Link to comment
Share on other sites

yup just like wat muddy said  ;D

shouldn't just do away with the error... but you can the ugly orange-ish line on your screen when it freaks out...

and in your case the @ is just telling php not to freaking out when you not able to connect to the database, and you can just output any error message you want... whenever i use that i always have the php error log saved!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.