Welcome Guest, Not a member yet? Register   Sign In
DB transaction error peculiarity
#1

(This post was last modified: 10-05-2023, 02:55 PM by codeus.)

Code:
Configuration:
CI v4.4.1
PHP v8.1.23
Ubuntu 22.04 LTS Jammy
mysql  Ver 15.1 Distrib 10.6.12-MariaDB

The transaction fails, but there's no indication in $this->db->error(). All the mariaDB tables are INNODB tables.


Code:
$this->db->transStart();
$this->db->query('INSERT'....);
$id = $this->db->insertID();
$this->db->query('UPDATE'....);
...
$this->db->transComplete();

if ($this->db->transStatus() === FALSE) {
    error_log('transaction error:' . print_r($this->db->error(), true));
    return false;
}


And in the log, there are numerous examples from the logging code like this:

Code:
PHP message: transaction error:
    code => 0
    [message] =>

Added db->error() to report on each individual SQL statements, each report indicates code is 0.
Is db-error() the wrong means to detect a transaction error, or is there actually an error?
Reply
#2

Did you try using try / catch with Exceptions?

PHP Code:
// When DBDebug in the Database Config must be true.

use CodeIgniter\Database\Exceptions\DatabaseException;

try {
    $this->db->transException(true)->transStart();
    $this->db->query('AN SQL QUERY...');
    $this->db->query('ANOTHER QUERY...');
    $this->db->query('AND YET ANOTHER QUERY...');
    $this->db->transComplete();
} catch (
DatabaseException $e) {
    // Automatically rolled back already.

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Using exceptions, it works ok. The only thing changed in the SQL was one of the queries was db->simpleQuery(), changed that to db->query().
Will see if it still causes problem reverting back to non-exception code.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB