Jump to content

Simple Questions


Bman900

Recommended Posts

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:)

Link to comment
https://forums.phpfreaks.com/topic/181946-simple-questions/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/181946-simple-questions/#findComment-959709
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.