patrickoq Posted July 22, 2011 Share Posted July 22, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242635-error-during-connection-to-db2-database/ Share on other sites More sharing options...
IrOnMaSk Posted July 22, 2011 Share Posted July 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242635-error-during-connection-to-db2-database/#findComment-1246183 Share on other sites More sharing options...
patrickoq Posted August 3, 2011 Author Share Posted August 3, 2011 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/242635-error-during-connection-to-db2-database/#findComment-1251123 Share on other sites More sharing options...
Muddy_Funster Posted August 3, 2011 Share Posted August 3, 2011 @ 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. Quote Link to comment https://forums.phpfreaks.com/topic/242635-error-during-connection-to-db2-database/#findComment-1251132 Share on other sites More sharing options...
IrOnMaSk Posted August 3, 2011 Share Posted August 3, 2011 yup just like wat muddy said 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/242635-error-during-connection-to-db2-database/#findComment-1251298 Share on other sites More sharing options...
patrickoq Posted August 5, 2011 Author Share Posted August 5, 2011 Thanks a lot Guys for comprehensive explanation Quote Link to comment https://forums.phpfreaks.com/topic/242635-error-during-connection-to-db2-database/#findComment-1252595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.