Bman900 Posted November 18, 2009 Share Posted November 18, 2009 I am reading a PHP book right now and am on the part where you make a connection to a database. Here is the code am looking at: <?php $dbc = mysqli_connect('host', 'username', 'password', 'databasename') or die('Error Connecting to MySQL server.'); ?> Now they tell me I don't have to close my first line statement as "or die" is still part of that said statement. But here is where they confuse me. This is the code where they tell me to run my query at: <?php $result = mysqli_query($dbc, $query); // they close the statement here and bellow or die('Error quering database'); ?> Wouldn't it be the same case here as "or die" is still part of my statement so technically I would not need to close the first line, right? Sorry I know this is kind of lame but I want to learn something right the first time and I go deep into the lessons by rewriting code several times to remember it and I don't want to learn it the wrong way. Thanks:) Quote Link to comment Share on other sites More sharing options...
oni-kun Posted November 18, 2009 Share Posted November 18, 2009 Technically you should not use or die(), As you should read in Daniel0's sig/tut. But yes you need it to be on the same line, closing the line will not allow the logic to parse and will just throw an error in the end. Quote Link to comment Share on other sites More sharing options...
trq Posted November 18, 2009 Share Posted November 18, 2009 Its a good point and in fact the second piece of code is incorrect. While your at it, you should read this on why the use of or die should die. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 the second example is incorrect. or die() is an extension to the query, therefore, having a closing ; on $result is not proper logic. or die() should be appended to $result as it is in the first example. read this though: http://www.phpfreaks.com/blog/or-die-must-die discusses the misuses of the or die() statement. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 18, 2009 Share Posted November 18, 2009 If this is your first programming language and you're already catching typos like that, then you're off to a good start. Quote Link to comment Share on other sites More sharing options...
Alex Posted November 18, 2009 Share Posted November 18, 2009 There are ridiculous amounts of typos in programming books (At least in all the ones that I've read). You'd think they would've been proofread by at least a few people who have enough experience to catch these things.. 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.