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".
In reply to Re: Class::DBI Intro
by dbwiz
in thread Class::DBI Intro
by trs80
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |