Jump to content

General question about if statements that's too difficult to describe in subject


matthewhaworth

Recommended Posts

Okay, look at the following code:

 

#1

<?php
if ( $link = mysql_connect($host, $user, $pass) )
{
    echo "The connection was successful";
}

 

#2

<?php
$link = mysql_connect($host, $user, $pass);
if ( $link = FALSE)
{
    echo "The connection was successful";
}

 

Which one should I use? When assigning variables within if statements does it return TRUE is the assignment was successful or does it return TRUE is the content of the variables is TRUE?

Of course! I'm half asleep, in the second example I did mean to use the comparison operator, not the assignment operator.. which makes a mokery of my whole question really.. but any more answers will be appreciated as I still don't feel satisfied.

 

Thanks so far.

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.