表别名从php不起作用

时间:2017-03-01 21:12:39

标签: php mysql

我要做的是从两个mysql表中选择列。 这个查询不适用于PHP脚本(我需要s.opis列):

$SQL="SELECT h.dzien, h.sektor, s.opis, h.start, h.stop, h.p, h.reg_date FROM harmonogram h,sektory s WHERE h.sektor=s.sektor AND h.dzien='".$dzien."' AND h.start='".$start."' ORDER BY h.dzien, h.sektor, h.start, h.stop;";
$wynik = mysql_query($SQL)
or die('Błąd zapytania');

但是,当我直接在mysql数据库上运行SQL时,它运行正常。

mysql> SELECT h.dzien, h.sektor, s.opis, h.start, h.stop, h.p, h.reg_date FROM harmonogram h,sektory s WHERE h.sektor=s.sektor AND h.dzien='Sun' AND h.start='08:00' ORDER BY h.dzien, h.sektor, h.start, h.stop;
+-------+--------+------+----------+----------+---+---------------------+
| dzien | sektor | opis | start    | stop     | p | reg_date            |
+-------+--------+------+----------+----------+---+---------------------+
| Sun   |      1 | tyl  | 08:00:00 | 08:15:00 | 0 | 2017-03-01 20:23:35 |
+-------+--------+------+----------+----------+---+---------------------+
1 row in set (0.00 sec)

此查询的先前版本工作正常,但未显示opis列

$SQL="SELECT dzien, sektor, start, stop, p, reg_date FROM harmonogram WHERE dzien='".$dzien."' AND start='".$start."' ORDER BY dzien, sektor, start, stop;";
$wynik = mysql_query($SQL)
or die('Błąd zapytania');

我认为问题可能在于别名。

对此有任何帮助吗?

1 个答案:

答案 0 :(得分:0)

添加为MacPrawn建议

IEnumerable<ListBoxItem>

更多地了解错误消息。

这是mysql表privilages问题。 现在解决了。

谢谢大家!