Jump to content

invader7

New Members
  • Posts

    6
  • Joined

  • Last visited

invader7's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I know that it's working as it's supposed to , this is what i said from the beginning , but my concern is why it prints false since the changes committed. The code is working ! The problem is the false print.
  2. MySQL , yes i'm pulling out my hairs it's very strange !! i'm going to look over my code again !
  3. Thanks for answering. No , with $mysqli->autocommit(FALSE); //var_dump($mysqli->commit());
  4. Thanks for answering , you are correct this example does not going with the point of prepared statements. It was just an example, i wanted to stay at the commit part. Let's say that the code is like this , with two individual queries include('config/functions.php'); $mysqli = connectionToDb(); $mysqli->autocommit(FALSE); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES (?,?)"); $stmt->bind_param('ss', $fn, $ln); $fn = 'stelios'; $ln = 'stelios2'; $stmt->execute(); $stmt->close(); $stmt = $mysqli->prepare("INSERT INTO customers (first_name,last_name) VALUES (?,?)"); $stmt->bind_param('ss', $fn, $ln); $fn = 'stelios'; $ln = 'stelios2'; $stmt->execute(); $stmt->close(); var_dump($mysqli->commit()); $mysqli->close(); My point with this code is to write to two different tables and to be sure that all the queries executed successfully. I want the second query to be executed ONLY if the first query succeeded and if the second query fails then the first query must rollback. I have some mechanisms (not shown here) in order to make sure that the first query is succeeded. Then after a successful second query i'm calling commit and everything works but the return value is FALSE. If i comment out commit in this code, then nothing is written in the tables. so this code returns TRUE to you ?
  5. Hello , this is my first post in this forum , i would like to see the following code and tell me your opinion , not about the security issues not about how good or bad it is. Its just a simple demonstration in order to show you the problem. <?php include('config/functions.php'); $mysqli = connectionToDb(); $mysqli->autocommit(FALSE); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES ('stelios','stelios2')"); $stmt->execute(); $stmt->close(); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES ('stelios3','stelios4')"); $stmt->execute(); $stmt->close(); var_dump($mysqli->commit()); $mysqli->close(); This is the code and the var_dump($mysqli->commit()); line prints false ! BUT , the inserts are in the database. If i comment out the commit line , then nothing is in the database. Can you advise ? Thanks !
×
×
  • 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.