envexlabs Posted September 8, 2008 Share Posted September 8, 2008 Hey, Just a quick question that occured today. Which method is better to grab rows from a mysql database, or are they exactly the same? method 1: $query = mysql_query(SOME QUERY); $result = mysql_fetch_assoc($query); method 2: $result = mysql_fetch_assoc(mysql_query(SOME QUERY)); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 Well, the first one creates an extra variable, but in reality, they're pretty much the same. The real best method would be a DBAL. =P Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 8, 2008 Share Posted September 8, 2008 my preferred method so i know when my SQL is wrong: $query = mysql_query(SOME QUERY) or die(mysql_error()." in SOME QUERY"); $result = mysql_fetch_assoc($query); otherwise, you're left guessing. Quote Link to comment Share on other sites More sharing options...
envexlabs Posted September 8, 2008 Author Share Posted September 8, 2008 thanks! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2008 Share Posted September 8, 2008 The first method permits error checking, error reporting, error logging, and error recovery, so that it could be used in a real life application. The second method does not, and would earn a C- in a programming class. Quote Link to comment 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.