Jump to content

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.