monkeytooth Posted December 18, 2009 Share Posted December 18, 2009 Alright since I wouldn't know where to begin to look for this ill admit I am hitting the form first. I don't want to muck it up my work, more than I have at least. So that said when one makes a update query or insert or connection.. whatever to mysql, via PHP its customary to have a "or die(...);" after the query in case anything fails. What I want to know is can I have something else, instead of a "or die(...);"? Could I put a variable there instead or anything? example instead of using: $update = mysql_query("UPDATE thisthat SET $foo='$bar' WHERE id='$ID'") or die('Error: '.mysql_error().'); could I do something like: $update = mysql_query("UPDATE thisthat SET $foo='$bar' WHERE id='$ID'") or $var1 = "whoops"; $var1msg = "Query Failed: update thisthat"; Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/ Share on other sites More sharing options...
premiso Posted December 18, 2009 Share Posted December 18, 2009 You may want to read: or die() must die. Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/#findComment-979892 Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2009 Share Posted December 18, 2009 Because or anything() does not address error recovery (what your code does when an error occurs), blindly continue execution, return a known/default value, output a useful error message and contain with the remainder of the presentation logic on the page, it really should not be used except for debugging purposes. Unless you want to use exceptions, all you really need to do is just use conditional logic so that you can address error recovery when an error occurs - http://www.phpfreaks.com/forums/index.php/topic,280845.msg1330662.html#msg1330662 Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/#findComment-979911 Share on other sites More sharing options...
monkeytooth Posted December 18, 2009 Author Share Posted December 18, 2009 OK, I am understanding the error catching. Though I am not trying to catch the errors per say. What I am trying to do is or want to know if possible is, can I do something else rather than pretty much for an exit of or kill the script. I have a custom error handler I have been working on cause of the way I am implementing AJAX style coding. Which the custom error handling works fine up until a sql query breaks. at which point like someone else pointed out. The code outside of the SQL still runs with default parameters. What I want to do is instead of using DIE or the method from the article link above is set a variable so I can trigger my error handler, problem is if its not possible I dont want to spend all day trying to make it work to find out that I can't then figuring out it cant work and having to go back over everything fixing it to work like it was prior to messing with it like I'm intent on. Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/#findComment-980116 Share on other sites More sharing options...
premiso Posted December 18, 2009 Share Posted December 18, 2009 You can easily use an if / else statement for what you want as PFM stated: if (!mysql_query($query)) { // set error var here } Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/#findComment-980123 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 like /set error variablehere would be $errortoday = "you just overworked the server"; then later echo $errortoday;\ and it would say that ive done it i know Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/#findComment-980129 Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2009 Share Posted December 18, 2009 I'm thinking that an explanation of what using or anything() actually does might help. Most functions return something that can be treated as either a TRUE or a FALSE value. In the code - somefunction() or anything(); When somefunction() returns a TRUE value, the anything() after the logical or is not evaluated due to short-circuit optimization (TRUE or xxxxx is always TRUE so the evaluation stops at that point.) When somefunction() returns a FALSE value, the or anything() causes the anything() statement to be evaluated/executed. The above is a simple conditional test. However, with an actual if(){}else{} conditional test you have the ability to both specify code that is to be execuited when the condition is true and when it is false. Quote Link to comment https://forums.phpfreaks.com/topic/185603-mysql-statement-or/#findComment-980162 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.