gammaman Posted May 13, 2008 Share Posted May 13, 2008 My table is not updating why? Here is the create table stuff mysql> create table Bank( -> accID int not null, -> balance float (10,2) not null, -> Primary Key (accID)); Query OK, 0 rows affected (0.06 sec) mysql> Insert into Bank (accID,balance) values (6,1000.00); Query OK, 1 row affected (0.01 sec) mysql> Alter table Bank ENGINE=innoDB; Query OK, 1 row affected (0.06 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> Set autocommit=0; Query OK, 0 rows affected (0.00 sec) Here is the code: <?php mysql_connect("localhost","fierm","13183"); mysql_select_db(fierm); mysql_query("BEGIN"); $result = mysql_query("Update Bank set balance='5000.00' where accID='6'"); echo "here"; if($result){ mysql_query("COMMIT"); } else{ echo "failed"; } ?> Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/ Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 Use mysqli_* functions, like so: mysqli_autocommit($dbc, FALSE); //Turns off autocommit on $dbc (connection) $result = "INSERT INTO test VALUES ('lol')"; if ($result) { mysqli_commit($dbc); } else { mysqli_rollback($dbc); } Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540420 Share on other sites More sharing options...
gammaman Posted May 13, 2008 Author Share Posted May 13, 2008 That did not work. Could it be due to the type of database I am using. Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540429 Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 You need to use InnoDB, which you are. Please put in the proper database connection variable...and make sure to use mysqli_connect(). Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540431 Share on other sites More sharing options...
gammaman Posted May 13, 2008 Author Share Posted May 13, 2008 It is still not working, but I should have mentioned that the page now loads blank which inicated a syntax error. I copied your code exactly, are you sure there is no error in your code. Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540438 Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 Woops, forgot to do the query. O_O mysqli_autocommit($dbc, FALSE); //Turns off autocommit on $dbc (connection) $result = mysqli_query("INSERT INTO test VALUES ('lol')", $dbc); if ($result) { mysqli_commit($dbc); echo "Query succeeded."; } else { mysqli_rollback($dbc); } Try a real query though. Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540439 Share on other sites More sharing options...
gammaman Posted May 13, 2008 Author Share Posted May 13, 2008 What am I doing wrong. <?php mysql_connect("localhost","fierm","13183"); $dbc = mysql_select_db(fierm); mysqli_autocommit($dbc); mysqli_query("BEGIN"); $result = mysqli_query("Update Bank set balance='5000.00' where accID='6'",$dbc); echo "here"; if($result){ echo "table updated"; mysqli_commit($dbc); } else{ mysqli_rollback($dbc); } ?> Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540441 Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 Did I say to use mysql_query("BEGIN")? >_> Here: <?php $dbc = mysqli_connect("localhost","fierm","13183", "fierm"); //Selects database on connection, GOOD //NEVER set $dbc to a mysql_select_db call mysqli_autocommit($dbc); //Don't need to query it with BEGIN $result = mysqli_query("Update Bank set balance='5000.00' where accID='6'",$dbc); echo "here"; if($result){ echo "table updated"; mysqli_commit($dbc); } else{ mysqli_rollback($dbc); } ?> Link to comment https://forums.phpfreaks.com/topic/105506-help-with-php-transactions/#findComment-540443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.