WideBlade Posted October 23, 2010 Share Posted October 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/216638-mysql-php-queries-syntax-not-clear/ Share on other sites More sharing options...
Pikachu2000 Posted October 23, 2010 Share Posted October 23, 2010 It's pretty self-explanatory: $result is the result resource from the execution of the query. If the query doesn't execute, echo the contents of mysql_error() and kill the script. Quote Link to comment https://forums.phpfreaks.com/topic/216638-mysql-php-queries-syntax-not-clear/#findComment-1125579 Share on other sites More sharing options...
eran Posted October 23, 2010 Share Posted October 23, 2010 The dot '.' operator is used to concatenate string in PHP. http://php.net/manual/en/language.operators.string.php Quote Link to comment https://forums.phpfreaks.com/topic/216638-mysql-php-queries-syntax-not-clear/#findComment-1125615 Share on other sites More sharing options...
WideBlade Posted October 26, 2010 Author Share Posted October 26, 2010 So, it's to combine these two things together? e.g. Query Failed: error? So wouldn't it work without the dot as well? Quote Link to comment https://forums.phpfreaks.com/topic/216638-mysql-php-queries-syntax-not-clear/#findComment-1126785 Share on other sites More sharing options...
gizmola Posted October 26, 2010 Share Posted October 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216638-mysql-php-queries-syntax-not-clear/#findComment-1126792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.