Back ticks in MySQL query using PHP
Posted: Mon Jan 05, 2009 7:00 pm
I thought that the back tick was an optional in MySQL queries and was surprised to find the following query give me an error:
but the following two queries did not... unless the tables and columns where back ticked through to as far as the 3rd example there was an error as:
Mysql 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 'tab, table_locations WHERE table_locations.tl_id = 1' AND `tab`.`t_tl_id`' at line 1
Can anyone explain why this might be?
Thanks
Code: Select all
<?php
// 1st example
$qry = ("SELECT tab.*, table_locations.tl_name FROM tab, table_locations WHERE table_locations.tl_id = $tl_id AND tab.t_tl_id = table_locations.tl_id");
?> Mysql 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 'tab, table_locations WHERE table_locations.tl_id = 1' AND `tab`.`t_tl_id`' at line 1
Code: Select all
<?php
// 2nd example
$the_qry = ("SELECT `tab`.*, `table_locations`.`tl_name` FROM `tab`, `table_locations` WHERE `table_locations`.`tl_id` = $tl_id AND `tab`.`t_tl_id` = `table_locations`.`tl_id`");
// 3rd example
$the_qry = ("SELECT `tab`.*, `table_locations`.`tl_name` FROM `tab`, table_locations WHERE table_locations.tl_id = $tl_id AND tab.t_tl_id = table_locations.tl_id");
?> Thanks