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!

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

AHHHHH okay that makes a lot more sense! Thanks!
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.