Jump to content

help with PHP transactions


gammaman

Recommended Posts

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

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.

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);
  }
?>

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);
  }
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.