0

.Hello, I'm reading through some code and am not sure if I'm understanding this fully. This is supposed to connect to a mysql database:

if (!$dblink[$dblinkname] = mysql_connect($dbhost, $dbuser, $dbpass, true)) {
        //Throw error message
    }

Is this saying that if the dblink's name is empty then attempt to mysql_connect()? If I'm wrong on this any pointers would be appreciated! Thanks!

mario
  • 1,503
  • 4
  • 22
  • 42

2 Answers2

1

The following code do the same thing as the one in your question

$dblink[$dblinkname] = mysql_connect($dbhost, $dbuser, $dbpass, true)
if (!$dblink[$dblinkname]) {
    //Throw error message
}

In your case, the result of the mysql_connect command is stored in your array and then the content of your array is evaluated to see if you have a connection or not.

A.D.
  • 1,160
  • 1
  • 8
  • 23
1

The statement is first assigning whatever value is returned by mysql_connect function to $dblink[$dblinkname] variable.

Now, if the connection is made, it will return the link resource and the condition will not be false hence it will not throw error.

But if connection is not made, the returned value would be false, which will make the condition(!$dblink[$dblinkname]) true, hence it will execute error handling code.

Vivek Vaghela
  • 1,075
  • 9
  • 16