Code Comments
Programming Forum and web based access to our favorite programming groups.i have three tables: User [id, name, surname, email] User_Login [id, login_id, password] User_Privilege [id, Privilege_Level] (id is pk) As mysql doesn't support multi table inserts, when i add a user i am having to call 3 functions, to add the data to each relevant table. What i am working on, is if there was an error, i am trying to simulate a rollback. My function looks like this:The help i need is with the function Rollback - i am looking to perform a multi-table delete, using a join, but i can't quite figure it out. What i am looking for is one sql statement that can look for any null values in a completely joined record - if its null, then the insert must've failed, therefore delete the record and its relevant joined data. eg, If the first two inserts are ok, then the third insert creates an error, it will delete the user information that was entered in the user details and the user login tables. An error generated in the first insert is ok as it will break from the function. I have written the following: SELECT user.* from user LEFT JOIN user_privilege ON user.id = user_privilege.id WHERE user_privilege.privilege_level IS NULL i think this is ok (can someone confirm for me?), but i can't translate it into a delete statement. Thanks for the help! ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forumsPHP:Function AddUser { status = InsertPersonalDetails(); if(status == false) { return false; } status = InsertLoginDetails(); if(status == false) { //need to delete information inserted into PersonalDetails (User) table Rollback(); return false; } status = InsertPrivilegeDetails(); if(status == false) { //now need to delete info from PersonalDetails (User) table and LoginDetails (User_Login) table Rollback(); return false; } }
Post Follow-up to this messageHave you looked at http://www.mysqlfreaks.com/mysql/ma...agridguide.html easy data tables - and more ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messagei was aware that you could only use transactions on innodb & DBD table types, whereas the one i'm using is isam, hence the need to emulate a rollback function. ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.