Jump to content

error handling


jimfog

Recommended Posts

I prefer to set error mode to Exception and catch that on failure.

Link to comment
Share on other sites

That doesn't matter, mysqli::query also returns false if a query fails, right?

So you think $all_query_ok=true; is redundant?

Link to comment
Share on other sites

I wasn't suggesting that, I was just suggesting that whether you are using PDO or mysqli is irrelevant for the example in post 23. You can use a variable to keep track of whether or not there were any errors, or you can just test each result to find out. It doesn't matter if you're using PDO or mysqli.

Link to comment
Share on other sites

Ι think this code must be OK now...I am going to test it either way:

   $connection->autocommit(FALSE);      $result1 =$connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','4')");      $result2=$connection->query("insert into business_users values('".$connection->insert_id."','".$address."' , '".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')");            if(!$result||!$result2)      {$connection->rollback();       $connection->autocommit(TRUE);       echo 'transaction failed';       return false;      }      else          {          $connection->commit();          $connection->autocommit(TRUE);          }
Link to comment
Share on other sites

After the queries are finished, should I always use autocommit(TRUE)?

Or the commit method is sufficient to turn on again the autocommit feature of the db? It is not clear to me.

 

Provided the fact of course that I do want to set it that way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...