Page 1 of 1

Proper query syntax

Posted: Sun Aug 07, 2005 10:14 pm
by taldos
Could someone please tell me the difference between teh following two statements.

Code: Select all

$my_sql = "SELECT * FROM `my_leads` WHERE (`read`='0' AND `owner_id`='".$my_id."')";

$my_sql = "SELECT * FROM my_leads WHERE (read=0 AND owner_id=".$my_id.")";
I have used syntax similar to the second statement for a while now and it has been working. All of a suddden today, everything is no longer working and I think this is the problem. Does it have anything to do with the way the tables are set up?

Posted: Sun Aug 07, 2005 10:54 pm
by Burrito
mysql allows you to use the backticks so that you can use reserved words, operators and keywords for table and field names.

ex:

a field name this-field would not be valid because of the minus (-) sign.

so if you tried this:

Code: Select all

select * from myTable where this-field = 'joe'
the query would bomb out...whereas

Code: Select all

select * from `myTable where `this-field` = 'joe'
would work.

Re: Proper query syntax

Posted: Sun Aug 07, 2005 11:20 pm
by harrisonad
As burrito said, they are the same, Yet I found these
taldos wrote:`read`='0'
read=0
string to integer is not the same though

Posted: Sun Aug 07, 2005 11:49 pm
by feyd
mysql does implicit conversion on numeric strings to integers/floats and back..

Posted: Sun Aug 07, 2005 11:51 pm
by harrisonad
oic

That's new to me. Thanks

Posted: Mon Aug 08, 2005 7:21 am
by taldos
Oh ok. in other words, "read" was a reserved word which I need to use the escape character for.

Thanks

Cheers :D