Re: [PHP] Re: Multiple queries in PHP
2009/1/25 Ashley Sheridan a...@ashleysheridan.co.uk On Sun, 2009-01-25 at 15:07 -0600, Shawn McKenzie wrote: Ashley Sheridan wrote: Hi all, I've run into a bit of a problem. I put together a query using mysql variables in the form set @m:= 0; with the select that uses it directly after. For any wondering, the select was using it as an incremental value which can't be hard coded, as the value will depend on the ordering of the results of the query itself. The problem seems to be that while phpMyAdmin would execute this double query perfectly well, php using mysql_query() was having problems, as apparently it can't actually run multiple queries. Now the full query looks something like this: mysql_query(SELECT @m:=0;); $query = SELECT * FROM( SELECT profiles.id, ROUND(AVG(rated.score)) AS `rating`, COUNT(rated.score) AS `total`, @m:=...@m+1 AS rank FROM `rated` LEFT JOIN `profiles` ON (profiles.id = rated.profile_id) GROUP BY rated.profile_id ORDER BY rating DESC, total DESC) AS ranking WHERE ranking.id=$id; $result = mysql_query($query); which seems to be working OK so far, but does anyone know of any potential pitfalls I might face when doing something like this? Thanks, Ash www.ashleysheridan.co.uk Might try the mysqli extension. mysqli_multi_query() -- Thanks! -Shawn http://www.spidean.com Unfortunately, I think the server this is going on to doesn't have that extension :( Ash www.ashleysheridan.co.uk This extension does not have to be installed. If your server is running php5, then this extension is installed -eddy
Re: [PHP] Re: Multiple queries in PHP
This extension does not have to be installed. If your server is running php5, then this extension is installed No it's not. The mysql extension no longer ships with php by default, you have to build it when you ./configure or install the external php-mysql package (depending on your o/s and/or how you built it). If you have the php-mysql package installed, then you have mysqli - but it's not there by default. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Multiple queries in PHP
2009/1/26 Chris dmag...@gmail.com This extension does not have to be installed. If your server is running php5, then this extension is installed No it's not. The mysql extension no longer ships with php by default, you have to build it when you ./configure or install the external php-mysql package (depending on your o/s and/or how you built it). If you have the php-mysql package installed, then you have mysqli - but it's not there by default. Yes this is right. This was my fault. I think I got it mixed up with another extension, sorry. -eddy
[PHP] Re: Multiple queries in PHP
Ashley Sheridan wrote: Hi all, I've run into a bit of a problem. I put together a query using mysql variables in the form set @m:= 0; with the select that uses it directly after. For any wondering, the select was using it as an incremental value which can't be hard coded, as the value will depend on the ordering of the results of the query itself. The problem seems to be that while phpMyAdmin would execute this double query perfectly well, php using mysql_query() was having problems, as apparently it can't actually run multiple queries. Now the full query looks something like this: mysql_query(SELECT @m:=0;); $query = SELECT * FROM( SELECT profiles.id, ROUND(AVG(rated.score)) AS `rating`, COUNT(rated.score) AS `total`, @m:=...@m+1 AS rank FROM `rated` LEFT JOIN `profiles` ON (profiles.id = rated.profile_id) GROUP BY rated.profile_id ORDER BY rating DESC, total DESC) AS ranking WHERE ranking.id=$id; $result = mysql_query($query); which seems to be working OK so far, but does anyone know of any potential pitfalls I might face when doing something like this? Thanks, Ash www.ashleysheridan.co.uk Might try the mysqli extension. mysqli_multi_query() -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Multiple queries in PHP
On Sun, 2009-01-25 at 15:07 -0600, Shawn McKenzie wrote: Ashley Sheridan wrote: Hi all, I've run into a bit of a problem. I put together a query using mysql variables in the form set @m:= 0; with the select that uses it directly after. For any wondering, the select was using it as an incremental value which can't be hard coded, as the value will depend on the ordering of the results of the query itself. The problem seems to be that while phpMyAdmin would execute this double query perfectly well, php using mysql_query() was having problems, as apparently it can't actually run multiple queries. Now the full query looks something like this: mysql_query(SELECT @m:=0;); $query = SELECT * FROM( SELECT profiles.id, ROUND(AVG(rated.score)) AS `rating`, COUNT(rated.score) AS `total`, @m:=...@m+1 AS rank FROM `rated` LEFT JOIN `profiles` ON (profiles.id = rated.profile_id) GROUP BY rated.profile_id ORDER BY rating DESC, total DESC) AS ranking WHERE ranking.id=$id; $result = mysql_query($query); which seems to be working OK so far, but does anyone know of any potential pitfalls I might face when doing something like this? Thanks, Ash www.ashleysheridan.co.uk Might try the mysqli extension. mysqli_multi_query() -- Thanks! -Shawn http://www.spidean.com Unfortunately, I think the server this is going on to doesn't have that extension :( Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php