ID: 9482
Updated by: torben
Old-Status: Open
Status: Closed
Bug Type: *General Issues
Assigned To: 

This isn't a bug; it's a result of the differing precedence for || and or (which
are otherwise identical, btw).

Try this: 

  $db = mysql_connect("localhost", "root") || print "error connecting";
  echo $db;

The output should be '1'. The reason is that || has higher precedence than =,
so PHP sees the above statement as:

  $db = (mysql_connect("localhost", "root") || print "error connecting");

...which means that $db is assigned the value of the expression in parens, which
in this case will always evaluate to 1, which is not a valid MySQL resource.

Next try this:

  ($db = mysql_connect("localhost", "web")) || print "error connecting ";
  echo $db;

The output should be 'Resource id #1', since the precedence has now been forced.
The other way to force precedence is to use the lower-precedence 'or', as you 

The operator precedence table can be found in the manual at:

Hope this helps,


Previous Comments:

[2001-02-27 10:52:12] [EMAIL PROTECTED]

$db = mysql_connect("localhost", "web") || print "error connecting   ".mysql_error()." 

$result = mysql_query("select * from attract") || print "error querying   
".mysql_error()." ".mysql_errno();
$i = 0;
while ($row = mysql_fetch_array($result)){ // && ($i++ < 5)){
        echo $row[0]." ".$row[1]."<br>";

this script will repeatedly give me invalid MySQL Link Resource Warnings, but by 
changing the "||" to "or" it will work fine.



ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to