I was searching for a way to insert data into two database tables in a single query in such a way that if one failed, neither saved (I don\'t want orphaned data). I came ac
Try:
$dbh->beginTransaction();
$query = "INSERT INTO content_subpages (title, url_referer) VALUES ('$pagetitle','$url_referer');
INSERT INTO ccm_main_menu (sub_item, sub_item_link,sub_item_sort_order) VALUES ('$pagetitle','$url_referer','$newsort')";
$dbh->exec($query);
$dbh->commit();
Btw, Simon Germain got a good point, Transaction will work with tables using InnoDB engine.