php - Using PDO and transactions, but I dont get error so rollback wont work. -
I am trying to create a simple class in PHP,
Db- & gt; Starting restriction (); } Function query ($ sql) {$ stmt = $ this- & gt; Db- & gt; Ready ($ sql); $ Stmt- & gt; Executed (); Return $ stmt->; FetchAll (); } Function lastInsertID () {return $ the-> Db- & gt; LastInsertId (); } Command command trance () {$ this-> Db- & gt; Committed (); } Function Rollback () {$ this- & gt; Db- & gt; Rollback (); } Function __destruct () {$ this- & gt; Db = null; }}
But when I do the following, I do not get any error, even if I do for the query, which results in the complete rollback function completely useless. Questions are still accumulated, even if queries can be completely messed up ..!
& lt ;? Php is required 'db_con.php'; $ Db = new db (); $ Db- & gt; Trans (); $ Nick = "WebbashShip". Include in 'User ID' ('UserID', 'Nick', 'Pass') values (zero, '$ _POST [Nick]', '$ _POST [Pass]') "; {$ Db-> Try the query ($ nick); $ NickID = $ db- & gt; Last Interactive Id (); Resonance $ niched; Include in $ Pers = "` webshop` person (person id ',' user id ',' fnm ',' lanam ','person', 'email') value (zero, $ nickid, '$ _POST [ First name] ',' $ _POST [last name] ',' $ _POST [person's name] ',' $ _ POST [email] ') "; Include $ Addr = "` webshop`. 'Address' (`Edit ID',` user id`, `road`,` city`, `zip`) value (zero, $ nickid, '$ _POST [address]', '' $ _POST [city] ',' $ _POST [zip] ') "; $ Db- & gt; Query ("INSERT" `` wshop`` `` `` `(` Person ID ', `UserID`,` FNA`, `LANA`,` PersonNR`, `Email`) value (Zero, $ Nickid, '$ _POST [first name]', '$ _POST [last name]', '$ _POST [person's name]', '$ _ POST [email]') "); $ db- & gt; query ($ addr );} Catch (exception $ e) {echo 'cat exception:', $ e-> getMessage (), "& lt;
Make sure that the PDO error mode is set to: PDO :: ERRMODE_EXCEPTION Otherwise, you will have to check the error status after each query.
Check for.
Comments
Post a Comment