ghostcoder Posted November 19, 2009 Share Posted November 19, 2009 I wonder if it's possible to prevent my script from totally failing if it doesn't find a table in a query? I've tried to suppress the error with the @ but it still ends the script. Is it possible? If it is I'm totally missing something. Quote Link to comment https://forums.phpfreaks.com/topic/182081-solved-prevent-script-fail-if-mysql-table-does-not-exit/ Share on other sites More sharing options...
gizmola Posted November 19, 2009 Share Posted November 19, 2009 We would need to see some code. Quote Link to comment https://forums.phpfreaks.com/topic/182081-solved-prevent-script-fail-if-mysql-table-does-not-exit/#findComment-960498 Share on other sites More sharing options...
roopurt18 Posted November 19, 2009 Share Posted November 19, 2009 It depends on how / what you're using to interact with the database. If, for example, you were using PDO and had it configured to throw exceptions, then you could wrap your code in a try...catch block. Quote Link to comment https://forums.phpfreaks.com/topic/182081-solved-prevent-script-fail-if-mysql-table-does-not-exit/#findComment-960530 Share on other sites More sharing options...
ghostcoder Posted November 19, 2009 Author Share Posted November 19, 2009 Hey guys, thanks for replying. I figured it out. My dyslexia must have been kicking in. normally I'll check the num_rows before I try to extract my result: if($getpoll->num_rows > 0){ but if the table doesn't exist in the actual query, then there is no result and that was ending the script. instead I just added: if($getpoll && $getpoll->num_rows > 0){ and also: if($getpoll){$getpoll->free_result();} at the end. This solved the problem. Feel free to delete this thread if you feel it's necessary. Sorry for starting the thread. Quote Link to comment https://forums.phpfreaks.com/topic/182081-solved-prevent-script-fail-if-mysql-table-does-not-exit/#findComment-960595 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.