Jump to content

sql syntax


ameliabob

Recommended Posts

As I read through the manuals and the phpMyAdmin I am confused about the use of the quotes( single and double) I have the following query string:

INSERT INTO presentation ( PresentationType, PresenterLastName, PresenterFirstName) VALUES ( 'A', 'ADSF', 'EUYTUJ');

phpMyAdmin shows single quotes around all of the labels.Should the $qry in mysql_query( $qry) have the " around everything? i.e. "INSERT INTO presentation ( PresentationType, PresenterLastName, PresenterFirstName) VALUES ( 'A', 'ADSF', 'EUYTUJ');" or is it just a string?

Link to comment
Share on other sites

In an SQL query, a single quote is used to make something a string. A backtick (`) is used to make a special name loose its meaning.If phpMyAdmin puts backticks around all object names (DBs, tables, columns, etc.), that's in order to ensure that whatever you've typed, it's going to be executed as expected. Unless the certain object name is not also some special keyword in SQL, it's safe not to use a backtick in other circumstances.Putting single quotes around all MySQL string is pretty much required so that you actually specify it's a string.Putting double quotes around the whole query is another thing though... this is a PHP tricky bit, not a MySQL tricky bit. PHP lets you have a string (in PHP context; literal string; no special meaning attached to it yet) surrounded by single or double quotes. If the string contains the same kind of quote, it must be escaped by having a "\" in front of it. Since MySQL queries will usually have a few single quotes to represent strings in an SQL query context, most queries are being written out surrounded by double quotes, in order to avoid the need for slashes.

Link to comment
Share on other sites

In an SQL query, a single quote is used to make something a string. A backtick (`) is used to make a special name loose its meaning.If phpMyAdmin puts backticks around all object names (DBs, tables, columns, etc.), that's in order to ensure that whatever you've typed, it's going to be executed as expected. Unless the certain object name is not also some special keyword in SQL, it's safe not to use a backtick in other circumstances.Putting single quotes around all MySQL string is pretty much required so that you actually specify it's a string.Putting double quotes around the whole query is another thing though... this is a PHP tricky bit, not a MySQL tricky bit. PHP lets you have a string (in PHP context; literal string; no special meaning attached to it yet) surrounded by single or double quotes. If the string contains the same kind of quote, it must be escaped by having a "\" in front of it. Since MySQL queries will usually have a few single quotes to represent strings in an SQL query context, most queries are being written out surrounded by double quotes, in order to avoid the need for slashes.
So to help me along with this Should be mysql_query("INSERT INTO presentation (..) Values(... 'ADSF', 'EUYTUJ')" ); ???
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...