View Single Post
Old 12-06-2007, 04:19 AM   #28 (permalink)
SOCK
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Backtracking a bit. I didn't notice this before, but it seems fairly obvious.
PHP Code:
// Connect to db
$db = new mysqli ('localhost''user''pass''dir''address''phone''email');

// Cant connect to db
if (mysqli_connect_errno())

{
    echo 
'Error: Could not connect to database.';

    exit;

What's with your connect statement?

Now an interesting question comes up. Why, if the connect statement looks so strange it doesn't exit the script when it hits the conditional block with the call to mysqli_connect_errno()? Well, one possible reason might be that it throws anything but a '1' or TRUE and so the conditional is skipped over. A better way to perform that would be something like this:

PHP Code:
// check to see if it throws ANYTHING but zero
if ( mysqli_connect_errno() !=) {
    
// an error occurred, exit

See the difference? Your conditional actually tests for TRUE. The function doesn't return TRUE. It returns 0 (if it's a good connection) or an error code.
SOCK is offline  
Reply With Quote