Re: is there an easy way to do a cascading delete using PEAR::DB?
| From: | Justin Patrin | Date: | Tue, 16 Nov 2004 21:20:09 +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-15581@lists.php.net to get a copy of this message | ||
On Tue, 16 Nov 2004 12:15:27 -0800 (PST), Stowe Spivey
<spiveyspivey@yahoo.com> 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 ?
>
There's no way that DB can do this for you. If your DB backend
supports "on delete cascade" I would suggest using that.
If you're using regular mysql or another non-relational system you can
write it yourself. If you use DB_DataObject you can (fairly easily)
write a cascading delete system which will do it for you
automatically. It will be nowhere near as fast as "on delete cascade"
or hard-coding the SQL yourself, though.
--
Justin Patrin