in reply to Class::DBI Intro
A few comments.
If the connect fails (see below), it returns "undef" and sets both "$DBI::err" and "$DBI::errstr". (It does not set "$!", etc.) You should generally test the return status of "connect" and "print $DBI::errstr" if it has failed.
It doesDELETE FROM page WHERE user_id = 1 DELETE FROM user WHERE user_id = 1
which can be quite long for large data sets.DELETE FROM page WHERE page_id = '1' DELETE FROM page WHERE page_id = '2' DELETE FROM page WHERE page_id = '3' DELETE FROM page WHERE page_id = '4' DELETE FROM page WHERE page_id = '5' DELETE FROM user WHERE user_id = '1'
FOREIGN KEY (user_id) references user (user_id) ON DELETE CASCADE, KEY user_id (user_id) # and replace "MyISAM" with "InnoDB" for both tables
You can then get the same behavior with
%dbh->do("DELETE FROM user WHERE user_id=1")and the database engine will take care of cascade deletiing the appropriate records in "page".
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Class::DBI Intro
by Corion (Patriarch) on Jul 30, 2003 at 12:38 UTC | |
by mojotoad (Monsignor) on Jul 30, 2003 at 19:32 UTC | |
Re: Re: Class::DBI Intro
by trs80 (Priest) on Jul 30, 2003 at 18:06 UTC | |
Re: Re: Class::DBI Intro
by salvadors (Pilgrim) on Aug 01, 2003 at 07:54 UTC |