English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

which one is right

("SELECT * FROM integers WHERE number = $num");

OR

("SELECT * FROM integers WHERE number = '$num' ");

should we put qutation mark ' around $num ? like '$num' ?

2007-11-09 16:16:19 · 5 answers · asked by ___ 4 in Computers & Internet Programming & Design

5 answers

The "proper" format advised by MySQL developers:

$query = "SELECT * FROM ` integers ` WHERE ` number ` = ' " . $num . " ' ";
(Spaces added for clarity)
Note the "back single quotes" ` around the names of the table and of the fields.
Note the "single quotes" around VALUES ( '5' if $num=5)
Note the split of the query: "SELECT..." . $num . "..."
You have three strings: "SELECT...", $num and " ' ", concatenated with " . "
Your first query may work on some machine and some versions of PhP and MySQL, but NOT on all.
The second may consider that $num is a string (between quotes), depending on the versions of the parsers...

2007-11-09 21:06:38 · answer #1 · answered by just "JR" 7 · 0 0

Unless the column definition for numbers is a string type, putting quotes around values are irrelevant.

2007-11-09 16:22:37 · answer #2 · answered by markee 2 · 0 0

It depends on the datatype of the "number" column. The right-hand side of the expression should be the same type as the left.

2007-11-09 16:21:27 · answer #3 · answered by Anonymous · 0 0

if $num returns a String then quote it otherwise no need to qoute it.

2007-11-09 16:52:21 · answer #4 · answered by AgilePro 3 · 1 1

Is your difficulty no longer being waiting to software on-the-fly sq. statements, or programming them in very own residing house page? (You create them in very own residing house page the comparable way you create them in the different language, basically employing very own residing house page syntax.)

2016-10-15 23:42:51 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers