Welcome Guest, Not a member yet? Register   Sign In
transStatus error
#1

Hi
What am I doing wrong?

PHP Code:
        $edb = \Config\Database::connect();
        $res $edb->prepare(function ($edb) {
            $query "select * from test limit :limit";
            return $edb->query($query);
        });
        $edb->transStart();
        $results $res
            
->execute(['limit' => 1])
            ->getResultArray();
        $edb->transComplete(); 
Cannot access protected property CodeIgniter\Database\Postgre\Connection::$transStatus
\Database\BasePreparedQuery.php at line 141
Reply
#2

It looks like the issue is caused by an incorrect query: https://codeigniter.com/user_guide/datab...d-bindings

On top of that, there may be a bug in CodeIgniter.

For now, I recommend skipping the transStart() and transComplete() methods so you can focus on resolving the query issue first.
michalsn.dev - mostly about CodeIgniter
Reply
#3

(06-16-2025, 11:27 AM)okatse Wrote: Hi
What am I doing wrong?

PHP Code:
        $edb = \Config\Database::connect();
        $res $edb->prepare(function ($edb) {
            $query "select * from test limit :limit";
            return $edb->query($query);
        });
        $edb->transStart();
        $results $res
            
->execute(['limit' => 1])
            ->getResultArray();
        $edb->transComplete(); 
Cannot access protected property CodeIgniter\Database\Postgre\Connection::$transStatus
\Database\BasePreparedQuery.php at line 141

For this:


I also had problems with CodeIgniter 4 when combining prepare() + PostgreSQL + transactions.

Instead of using prepare() use parameterized queries directly with query() or table() something like:

Code:
$edb = \Config\Database::connect();
$edb->transStart();

$query = "SELECT * FROM test LIMIT ?";
$results = $edb->query($query, [1])->getResultArray();

$edb->transComplete();

? is used for positional binding — this works well in PostgreSQL and avoids the internal issue with $transStatus

I have not tested above but hope that may help.
Reply
#4

A fix has already been prepared and will be included in an upcoming release.

The error occurred due to an issue in the code. Here's the corrected version:
PHP Code:
        $edb = \Config\Database::connect();
        $res $edb->prepare(function ($edb) {
            $query "select * from test limit :limit:";
            return $edb->query($query);
        });
        $edb->transStart();
        $results $res
            
->execute(1)
            ->getResultArray();
        $edb->transComplete(); 

Thank you for posting about this. It helped us identify and fix a bug.
michalsn.dev - mostly about CodeIgniter
Reply
#5

Thank you for your quick response.

Yes, I confirm that if the SQL query is incorrect, an error message is displayed "Connection::$transStatus"
Reply




Theme © iAndrew 2016 - Forum software by © MyBB