[PHP-DB] multiple queries in the same request

2005-06-20 Thread Gabriel B.
I have a table with some relational values, that really saves me on
selects, but gives me a weird error in the insert...

in the DB i have this 2 tables data and categories:
data(
id int
category tinyint ),
categories (
id tinyint
description varchar )

for selects i can use a single query with a left join.

but to populate the table without having to use magic numbers in my
code i've come up with:

SELECT (@category_id:=id) FROM categories WHERE description = cat1;
REPLACE INTO data VALUES( 10, @category_id);

i send this as a single query in PHP and it returns an error quoting
everything after the first ;

anyidea if i can't send several queries at once? any workaround?

Thanks,
Gabriel

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



Re: [PHP-DB] multiple queries in the same request

2005-06-20 Thread Bruno Ferreira

Gabriel B. wrote:


SELECT (@category_id:=id) FROM categories WHERE description = cat1;
REPLACE INTO data VALUES( 10, @category_id);

i send this as a single query in PHP and it returns an error quoting
everything after the first ;

anyidea if i can't send several queries at once? any workaround?
 

   You can't send multiple queries in an SQL statement. You can just 
split that in two separates queries. It's not really slower by any 
practical means because the DB system would have to execute them both 
anyway.


   -- Bruno Ferreira
---
[This E-mail scanned for viruses by Declude Virus]

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



Re: [PHP-DB] multiple queries in the same request

2005-06-20 Thread Bruno Ferreira

Gabriel B. wrote:


   You can't send multiple queries in an SQL statement. You can just
split that in two separates queries. It's not really slower by any
   



I'm not really concerned about performance. i'm *really* concerned
about race conditions.

I have more than 3mi hits per day. the chance that two pairs of
queries will run consecutively is imense.
 

   Then you need to use transactions, which fill your purpose :) I 
presume you're using MySQL or Postgres, google for START TRANSACTION and 
COMMIT.


   -- Bruno Ferreira