I am having issues with SQL.
This SQL statement:
SELECT * from chat WHERE id=16
Outputs:
Array ( [id] => 16 [from] => 5 [to] => 6 [message] => Example Message
[time] => 1337674546 )
The following SQL statement:
SELECT * from chat WHERE from=5
Outputs the error:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘from=5’ at line 1
As you can see, the second statement should return the same result but it does not.
I am using a new install of XAMPP which includes:
Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
MySQL client version: mysqlnd 5.0.8-dev – 20102224 – $Revision: 310735 $
It seems like I am missing something obvious here, but I can’t figure out what is going on.
change the second query to:
from is a reserved keyword that you should always avoid using or at least quote to make it work.