In the code below I connect to the database and then throw an exception if it fails. If it succeeds I print a message and then return with $db which I thought was the database object. But it doesn't execute the rest of the script after that point. If I take out the return then it does the print commands that follow the code block.
Obviously I am not understanding the use of return. Can anyone help me understand this better? Do I not need to use a return so that I can access the database further in the code?
Thanks.
<?php
// First need to connect to database
$pword = "xyz213";
echo "<p>Attempting to connect to omgma_members database with $pword password at line:" . __LINE__ ."</p>";
@$db = new mysqli("localhost", "omgma_omgmauser", $pword, "omgma_members");
if (mysqli_connect_errno() > 0)
{
$db_err = "db_connect cound not connect to database:<br/> " .mysqli_connect_error();
throw (new Exception($db_err));
}
else
{
echo "Connection worked! <br>";
return $db;
}
echo "<p>This is where the login test starts! <br />";
echo "Trying to login as $username using password: $passwd</p>";
//This is where the login logic will go...
print "</div>"; //closes the maincontent div
include ('includes/footer.inc');
?>