Re: [PHP] Multiple queries in PHP

2009-01-26 Thread Per Jessen
Ashley Sheridan wrote:

 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.

I don't know about the PHP mysql_query(), but the MySQL C API works fine
with multiple queries, it just has to be specifically enabled - the
default is one query per call. 
However, it looks like the multiple query option is not supported by
PHP: 

http://php.net/manual/en/mysqli.real-connect.php

For security reasons the MULTI_STATEMENT flag is not supported in PHP.
If you want to execute multiple queries use the mysqli_multi_query()
function.



/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple queries in PHP

2009-01-26 Thread Chris

Per Jessen wrote:

Ashley Sheridan wrote:


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.


I don't know about the PHP mysql_query(), but the MySQL C API works fine
with multiple queries, it just has to be specifically enabled - the
default is one query per call. 
However, it looks like the multiple query option is not supported by
PHP: 


http://php.net/manual/en/mysqli.real-connect.php

For security reasons the MULTI_STATEMENT flag is not supported in PHP.
If you want to execute multiple queries use the mysqli_multi_query()
function.


Same for mysql_query:

mysql_query() sends a unique query (multiple queries are not supported)...

--
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] Multiple queries in PHP

2009-01-25 Thread Stuart
2009/1/25 Ashley Sheridan a...@ashleysheridan.co.uk:
 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?

It's a security feature to prevent SQL injection. AFAIK you'll have no
problems so long as all calls to mysql_query happen on the same DB
connection so you might want to start using the linkid parameter.

-Stuart

-- 
http://stut.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple queries in PHP

2009-01-25 Thread Richard Lynch
PHP/MySQL and the various functionality such as @var are all
per-connection expressly so that you CAN do this type of stuff.

I'd be pretty shocked if you had any problems.

-- 
Some people ask for gifts here.
I just want you to buy an Indie CD for yourself:
http://cdbaby.com/search/from/lynch



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] multiple queries, one transaction

2005-05-20 Thread Richard Lynch
On Fri, May 20, 2005 2:02 pm, mayo said:
 I have a site where I need to do multiple queries in sequence.

In sequence, or as one single atomic un-interruptable action?

Cuz, like, just doing them in sequence is real straight forward:

$query = select ... ;
$meaningful_variable_names_are_good = mysql_query($query...
$query = select ... ;
$another_good_variable = mysql_query($query...

 I see there is a way to do consider all querys and to fail the entire
 procedure if one query fails. It's a BEGIN and COMMIT statement.

That is called a transaction.

And it is rather hefty performance penalties on your database.

And you need your tables to be innoDB or ??? but not the default MyISAM in
MySQL.

 mysql_query(BEGIN); // starts the transaction


Just put your queries in here.

ONLY do this if the queries succeed!
If they fail, do mysql_query(ROLLBACK);

 mysql_query(COMMIT); // ends the transaction

 I'm just not certain how it's used.

It's a lot easier to do the queries (you did all the hard work already)
than it is to figure out if you REALLY need them or not...

If you can avoid the transaction, and still have quality data and quality
application, you can gain significant performance that way...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Multiple Queries

2004-01-15 Thread Arthur Pelkey
$result = mysql_query(SELECT * FROM classes3 WHERE c_d_sun='1' AND
c_s_sun_1_hr='5'); 
while($row = @ mysql_fetch_array($result)) {
if($row[c_s_sun_1_hr] != 5) {
echo n/a;
} else {
echo
$row[c_s_sun_1_hr]:$row[c_s_sun_1_min]$row[c_s_sun_1_dn]br;
echo a title=\$row[c_desc]\$row[c_title]/a;
}
}

I have multiple segments of this, the query and the formatting are
different, is there another way to go about this?


-Original Message-
From: Humberto Silva [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 15, 2004 10:52 AM
To: [EMAIL PROTECTED]
Subject: RE: [PHP] Multiple Queries 

Can you paste the code please...

 
Humberto Silva
World Editing
Portugal
 


-Original Message-
From: Arthur Pelkey [mailto:[EMAIL PROTECTED] 
Sent: quinta-feira, 15 de Janeiro de 2004 15:46
To: [EMAIL PROTECTED]
Subject: [PHP] Multiple Queries 


I am new this.

I have a page that has multiple queries on it, I want to do doing the
following:

Query a mysql db multiple times in the same page, but i must be missing
something, I keep getting these AFTER the first queryis successful:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in /path/php_file.php on line line_number

Can someone point in the right direction on how to do multiple queries,
some are not querying the same db btw.

-Art

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Multiple Queries

2004-01-15 Thread CPT John W. Holmes
From: Arthur Pelkey [EMAIL PROTECTED]

 I have a page that has multiple queries on it, I want to do doing the
 following:

 Query a mysql db multiple times in the same page, but i must be missing
 something, I keep getting these AFTER the first queryis successful:

 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
 result resource in /path/php_file.php on line line_number

 Can someone point in the right direction on how to do multiple queries,
 some are not querying the same db btw.

There's no real trick to it. You can have as many mysql_query() calls as you
want. You probably just need to check that you're assigning the result of it
to a unique variable each time and not overwriting results or rows from
previous queries.

Post your code if you want, but your error means your query is failing or
you're using the wrong variable in one of the mysql_fetch_*() functions.
Using mysql_error() will help here.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple queries

2002-05-31 Thread Analysis Solutions

Heya:

On Fri, May 31, 2002 at 09:55:27AM +0100, Caspar Kennerdale wrote:

 I have one table, with a name and info about the project and upto 5 
 urls of where the jpeg lies.

Are you talking about five fields in the table containing up to five
URI's for each project?  That's not cool.  You should normalize that
structure.  Put the project info in one table and then the URI's in
anohter.  This allows you to efficiently store as few or as many URI's
as your heart desires.


 Now, I then have a piece of javascript which tells frame 2 to update 
 itself.

And what about people looking at your site who don't have Java'sCrap 
running?


 So I have parsed the record ID to it and it then open a query to the
 database and outputs the relevant information about the artworks. Lastly a
 third query is also sent to the database to see if there are any other
 projects in the gallery by the same artist- and then create a list of
 related links.

Sounds right.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Multiple queries on multiple databases

2002-05-24 Thread John Holmes

Just use MySQL_select_db() to switch between databases between your
queries. Remember to switch back, too.

Or you can just give the database name in your query:

SELECT * FROM database.table WHERE ...

---John Holmes...

 -Original Message-
 From: d3crypt [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 24, 2002 5:35 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Multiple queries on multiple databases
 
 Hello,
 
 I'd like to know the method to connect and query multiple databases in
 the same php script ...
 
 I've to do something like this :
 
 do query on db1_on_server_1
   while( get results of query on db1_on_server_1){
   do query on db2_on_server_2
   }
 
 the structure of the db is this one :
 
 # Table structure for table 'attendees' in db 'training2'
 #
 CREATE TABLE attendees (
attendee_ID int(8) NOT NULL auto_increment,
training_requester_ID int(8),
PRIMARY KEY (attendee_ID),
UNIQUE attendees_ID (attendee_ID)
 );
 
 # Dumping data for table 'attendees'
 #
 INSERT INTO attendees (attendee_ID, training_requester_ID) VALUES (
 '1', '299');
 
 
 # Table structure for table 'people_info' in db 'octopus'
 #
 CREATE TABLE people_info (
id int(255) DEFAULT '0' NOT NULL,
l_name varchar(255) NOT NULL
 );
 
 # Dumping data for table 'people_info'
 #
 INSERT INTO people_info (id, l_name) VALUES ('299', 'Forseilles');
 
 
 I've tried the following script, but it gives me a 'Warning: Supplied
 argument is not a valid MySQL result resource in
 g:\htdocs\training\viewmytrainings.php on line 23' :
 
 ?
 
 $octopus=localhost,,,octopus;
 $training=localhost,,,training2;
 
 function connect($database){
   $array=explode(,, $database);
   $host=$array[0];
   $user=$array[1];
   $pass=$array[2];
   $db=$array[3];
 
   $connect=mysql_connect($host,$user,$pass) or die (unable to
 connect host $hostbr);
   mysql_select_db($db) or die (unable to select $db in
 $hostbr);
   return($connect);
   }
 
 $connect1=connect($training);
 $connect2=connect($octopus);
 
 $query=select * from attendees order by training_ID asc;
 $result=mysql_query($query, $connect1);
 $row=mysql_fetch_row($result);
 
 echo $row[1];
 
 $queryx=select l_name from people_info where id='$row[1]';
 $resultx=mysql_query($queryx, $connect2);
 $rowx=mysql_fetch_row($resultx);
 
 echo $rowx[0];
 
 ?
 
 
 Any idea ? Thanks for your help ...
 
 (PHP Version 4.0.6)
 
 
 --
 d3crypt aka p
 $ drink bottle; opener
 bottle: cannot open
 opener: not found
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php