Jump to content

[SOLVED] Query syntax (qoutes)


hostfreak

Recommended Posts

Another thing that confuses me is that in php you can only parse a variable in double quotes unless you use the concatenation operator. However, if your doing a query (mysql_query) it will parse the variable surrounded by the single quotes.

 

I am assuming it's only within the mysql_query function that php will parse the variable like this? Do to the fact that inside that function, the quotes will be irrelevant (being as they will then be parsed by mysql)?

Link to comment
Share on other sites

Another thing that confuses me is that in php you can only parse a variable in double quotes unless you use the concatenation operator. However, if your doing a query (mysql_query) it will parse the variable surrounded by the single quotes.

 

I am assuming it's only within the mysql_query function that php will parse the variable like this? Do to the fact that inside that function, the quotes will be irrelevant (being as they will then be parsed by mysql)?

 

Keep in mind that the PHP parser is interpreting the entire string before it gets sent to the MySQL query. So, when you have a variable within the single quotes, PHP only knows that it is part of a larger string within the double quotes. If you were to echo the SQL statement out to the screen, you would see what is actually sent to the MySQL parser:

<?php
$name = 'Obsidian';
$sql = "SELECT * FROM users WHERE username = '{$name}'";
echo $sql; // SELECT * FROM users WHERE username = 'Obsidian'
?>

Link to comment
Share on other sites

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.