T
T
Terion2011-11-07 14:09:30
PHP
Terion, 2011-11-07 14:09:30

Same MySQL query works through PhpMyAdmin but doesn't work through script?

I do not understand. There is such a request (you need to select the position of the player ± 2 positions, it didn’t work out better).

$uid = 2;<br/>
 $rate_table = $this-&gt;db-&gt;query('SET @rank=0;<br/>
 CREATE TEMPORARY TABLE `rank_table` AS (<br/>
 SELECT @rank:[email protected]+1 AS rank,`users`.*,IFNULL(SUM(`g`.`units`),0) as sum<br/>
 FROM `users`<br/>
 LEFT OUTER JOIN (SELECT * FROM `game_rounds` WHERE `game_rounds`.`final`=1) g ON `users`.`id`=`g`.`uid`<br/>
 GROUP BY `users`.`id`<br/>
 ORDER BY `sum` DESC<br/>
 );<br/>
 SET @user_rank = (SELECT `rank` FROM `rank_table` WHERE `id`='.$uid.');<br/>
 SELECT * FROM `rank_table` WHERE `rank`&lt;[email protected]_rank+2 AND `rank`&gt;[email protected]_rank-2')-&gt;result();

When I run it through PhpMyAdmin, I get quite a good and correct result.
When I feed it to the script (in the example - through Codeigniter) - it knocks out a syntax 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 'CREATE TEMPORARY TABLE `rank_table` AS ( SELECT @rank:[email protected]+1 AS rank,`users`' at line 2

At the same time, it shows which request was sent to the database, I just copy it, paste it into PhpMyAdmin - and get the result.
I feed the query through PDO->query () - it returns an empty result (that is, in the returned PDO object there is only the query itself)
I DON'T UNDERSTAND ANYTHING!
I won't be indebted for help.
Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
persona, 2011-11-07
@Terion

Break requests by; and do them one by one. Multiqueries may not be executed depending on the settings on a particular server.

W
WebSpider, 2011-11-07
@WebSpider

There is also such a thing as mysqli_multi_query , but I'm not sure that it can be easily screwed with CodeIgniter

V
Vitaly Zheltyakov, 2011-11-07
@VitaZheltyakov

How does the request appear in the xDebug profile?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question