Jump to content

MySQL PHP queries-syntax not clear


WideBlade

Recommended Posts

So I've go this script that adresses lots of queries to MySQL.

It works perfectly, but I was just curious about a part of the qury syntax:

 

$result = mysql_query($query)
or die ("Query Failed: " . mysql_error());

 

What's the deal with the dot between the Failed: and the mysql_error?

 

Link to comment
https://forums.phpfreaks.com/topic/216638-mysql-php-queries-syntax-not-clear/
Share on other sites

You really need to read the php manual.  It explains these concepts very well.

 

 

"Query Failed: " is a string constant.  You can tell that by double quotes around the string.  It would actually be better practice here to use single quotes, because in PHP double quotes cause the php interpreter to have to parse the string looking for php variables to "interpolate"  (search and replace, basically).

 

Then you have the mysql_error().  This is a function, that when you look it up, you'll see it returns a string. 

 

When you look up the die() function you'll see that it is just another name for exit().  Exit accepts a single parameter that again needs to be a string or an integer.  So what you need to have for input in this case is a single string.

 

So you are passing as input, a string AND a function that returns a string.  The only way this will be valid is if you can combine the two into a single string, and as explained  by eran, you do that with the '.'  (concatenation) operator.

 

 

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.