Tommy D’s Sexy Blog

TagLine Here

PHP Tip, writing a MySQL query

Filed under: PHP Tips — Tommy D. at 12:32 pm on Monday, July 4, 2005

When writing a MySQL query, it is not necessary to use escaped double quotes (\”) when representing literal strings within the query. Single quotes (apostrophes) will work fine. For example, the following two lines of code will perform the same query:

$result = mysql_query(“SELECT foo FROM bar WHERE baz=\”test\”", $db);
$result = mysql_query(“SELECT foo FROM bar WHERE baz=’test’”, $db);

As will this code perform the same query:

$var = ‘test’;

$result = mysql_query(“SELECT foo FROM bar WHERE baz=’$var’”, $db);

There is not necessarily a performance gain between one method or the other, but using single quotes instead of escaped double quotes greatly improves the readability of your code.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

 

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin