Re: is there an easy way to do a cascading delete using PEAR::DB?
| From: | Andrew Nagy | Date: | Tue, 16 Nov 2004 20:35:11 +0000 |
| Subject: | Re: is there an easy way to do a cascading delete using PEAR::DB? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15572@lists.php.net to get a copy of this message | ||
Stowe Spivey wrote:
I have some code that works but I am moving what I can over to DB code. Problem: Several tables, B, C, D are related to table A. When I delete A, I need to delete all the other tables that have records related to that record. Solution: Use PHP to do multiple delete sql statements OR ?If you are using a database (such as Postgres or MySQL with InnoDB) that supports it, it would be many times faster to use the database itself. CREATE TABLE user ( id int(11) not null primary key, fname varchar(100) not null, lname varchar(100) not null ); CREATE TABLE user_address ( id int(11) not null primary key, user_id int(11) not null references user(id) on delete cascade, city varchar(100) not null, st char(2) not null, zip varchar(10) ); Look into using stored procedures or triggers, any batch of SQL statements will run faster when coming directly from the database rather than in PHP. Cheers Andrew