hi folks
I get an error when I run an query in phpmyadmin, the same sentence in a php script or console works perfectly
Some interesting information:
Linux entel 2.6.19.dic5-entel #1 Tue Dec 5 15:49:34 CLST 2006 i686 GNU/Linux
localhost
* Server version: 5.0.24a-Debian_9-log
* Protocol version: 10
* Server: Localhost via UNIX socket
* User: root@localhost
* MySQL charset: UTF-8 Unicode (utf8)
phpMyAdmin - 2.9.1.1 / 2.9.2
* MySQL client version: 5.0.24a
* Used PHP extensions: mysql
The query look this:
###########################################
*************IN PHPMYADMIN
Select c.id as empresa_id, c.empresa as empresa_nombre, g.id as guia_id, g.comprador as guia_comprador_id, g.numero_guia, gd.numero_guia, gd.producto as gd_producto_id, SUM(gd.cantidad) as cantidad_C, p.id as producto_id, p.nombre, p.precio from clientes as c, guias as g, guias_datos as gd, productos as p where c.id = '32' and c.id = g.comprador and gd.numero_guia = g.numero_guia and gd.producto=p.id and g.lock='1' GROUP BY gd.producto
Error
SQL query: Documentation
SELECT c.id AS empresa_id, c.empresa AS empresa_nombre, g.id AS guia_id, g.comprador AS guia_comprador_id, g.numero_guia, gd.numero_guia, gd.producto AS gd_producto_id, SUM( gd.cantidad ) AS cantidad_C, p.id AS producto_id, p.nombre, p.precio
FROM clientes AS c, guias AS g, guias_datos AS gd, productos AS p
WHERE c.id = '32'
AND c.id = g.comprador
AND gd.numero_guia = g.numero_guia
AND gd.producto = p.id
AND g.lock = '1'
GROUP BY gd.producto
LIMIT 0 , 30
MySQL said: Documentation
#1064 - 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 'lock = '1' GROUP BY gd . producto
LIMIT 0, 30' at line 1
**************IN CONSOLE
Database changed
mysql> Select c.id as empresa_id, c.empresa as empresa_nombre, g.id as guia_id, g.comprador as guia_comprador_id, g.numero_guia, gd.numero_guia, gd.producto as gd_producto_id, SUM(gd.cantidad) as cantidad_C, p.id as producto_id, p.nombre, p.precio from clientes as c, guias as g, guias_datos as gd, productos as p where c.id = '32' and c.id = g.comprador and gd.numero_guia = g.numero_guia and gd.producto=p.id and g.lock='1' GROUP BY gd.producto;
+------------+------------------+---------+-------------------+-------------+-------------+----------------+------------+-------------+--------+--------+
| empresa_id | empresa_nombre | guia_id | guia_comprador_id | numero_guia | numero_guia | gd_producto_id | cantidad_C | producto_id | nombre | precio |
+------------+------------------+---------+-------------------+-------------+-------------+----------------+------------+-------------+--------+--------+
| 32 | AMD Corporation. | 1 | 32 | 40851 | 40851 | 1 | 10549 | 1 | Pan | 420 |
+------------+------------------+---------+-------------------+-------------+-------------+----------------+------------+-------------+--------+--------+
1 row in set (0.00 sec)
mysql>
########################################
When I run the "same" sentence without " and g.lock = 1" works fine under phpmyadmin
Like this.
Select c.id as empresa_id, c.empresa as empresa_nombre, g.id as guia_id, g.comprador as guia_comprador_id, g.numero_guia, gd.numero_guia, gd.producto as gd_producto_id, SUM(gd.cantidad) as cantidad_C, p.id as producto_id, p.nombre, p.precio from clientes as c, guias as g, guias_datos as gd, productos as p where c.id = '32' and c.id = g.comprador and gd.numero_guia = g.numero_guia and gd.producto=p.id GROUP BY gd.producto';
maybe phpmyadmin recognize "lock" such as "internal reserved word"?
See this
ALTER TABLE `guias` CHANGE `lock` `l` INT( 2 ) NOT NULL
I changued "lock" to "l", then I try the query (with "and g.l ='1'" of course)... and it's works!
I did an exclusive database and table to try this.
CREATE DATABASE `bug` ;
CREATE TABLE `bug` (
`id` MEDIUMINT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL ,
`lock` MEDIUMINT( 10 ) NOT NULL
) ENGINE = MYISAM ;
INSERT INTO `bug` ( `id` , `name` , `lock` )
VALUES (
NULL , 'nicolas', '1'
), (
NULL , 'nicolas2', '1'
);
**************
####PHPMYADMIN
SQL query: Documentation
SELECT b.id, b.name, b.lock
FROM bug AS b
WHERE b.lock =1
LIMIT 0 , 30
MySQL said: Documentation
#1064 - 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 'lock FROM bug as b where b . lock = 1
LIMIT 0, 30' at line 1
####CONSOLE
mysql> use bug
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT b.id,b.name,b.lock FROM bug as b where b.lock = 1;
+----+----------+------+
| id | name | lock |
+----+----------+------+
| 1 | nicolas | 1 |
| 2 | nicolas2 | 1 |
+----+----------+------+
2 rows in set (0.00 sec)
mysql>
***********
SELECT * FROM `bug` WHERE 1 LIMIT 0 , 30 works in phpmyadmin
SELECT * FROM `bug` WHERE lock = 1 does not work in phpmyadmin
SELECT name,lock FROM bug does not work in phpmyadmin
SELECT lock FROM `bug` WHERE lock = 1 does not work in phpmyadmin ****
*** UPDATE:
The source code of generated page shows:
<span class="syntax"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span> <span class="syntax_alpha syntax_alpha_reservedWord">LOCK</span>
I think that phpmyadmin can not recognize when "lock" its the name of a field or is a reserved word
*** UPDATE:
phpMyAdmin-2.9.2-all-languages-utf-8-only have the same bug
sorry for my english
Salduos desde Chile!
Logged In: YES
user_id=1071835
Originator: YES
select 'lock' from 'bug' where 'lick' = '1' fail.
SELECT * FROM 'bug' WHERE 'lock' = '1' fail.
SELECT 'b.lock' FROM 'bug as b' fail.
Using " instead ' fail too.
Logged In: YES
user_id=1071835
Originator: YES
SELECT * FROM `bug` WHERE `lock` = '1'
works fine
Logged In: YES
user_id=210714
Originator: NO
Fixed for 2.10, please confirm using our svn version or the demo (development version) at phpmyadmin.net.
Logged In: YES
user_id=1071835
Originator: YES
No.
I am using
http://pma.cihar.com/trunk/
Latest development version, database "entel"
I did the same querys
SELECT 'lock'
FROM 'bug'
WHERE 'lock' = '1'
LIMIT 0 , 30
And does not work
consulta SQL: Documentación
##############
SELECT LOCK FROM bug
MySQL ha dicho: Documentación
#1064 - 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 'lock from bug' at line 1
********
<span class="syntax"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span> <span class="syntax_alpha syntax_alpha_reservedWord">LOCK</span> <span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_alpha syntax_alpha_identifier">bug</span></span>
********
####
SELECT 'b.lock' FROM 'bug as b' NO
SELECT * FROM 'bug' WHERE 'lock' = '1' NO
Using " instead ' fail too.
SELECT * FROM `bug` WHERE `lock` = '1' YES
Logged In: YES
user_id=1383652
Originator: NO
entel,
i didn't check your query, but you have to use "`" (backticks), "'" is only for variables.
Logged In: YES
user_id=1383652
Originator: NO
SELECT `lock` FROM `bug` WHERE `lock` = '1' works on demo
Logged In: YES
user_id=210714
Originator: NO
The real bug I fixed here is better tested with
SELECT bug.lock
FROM bug
WHERE bug.lock =1
this gives an error 1064 on http://pma.cihar.com/STABLE
and works on http://pma.cihar.com/trunk/