gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.3k stars 279 forks source link

Mysql PDO transaction problem #918

Closed marios88 closed 1 year ago

marios88 commented 1 year ago

I have run into this "bug" when using transactional grouped inserts https://bugs.php.net/bug.php?id=61613

But unfortunately i cannot access the prepared statement to run nextRowset()

For now my solution is to run each insert in a loop, but i am looking for a more elegant solution

\R::begin();
$queries =[ ... ];
try{
    foreach ($queries as $query) {
        \R::exec($query);
    }
    \R::commit();
}catch (Exception $e) {
    \R::rollback();
}
gabordemooij commented 1 year ago

Interesting, I will take a look.

gabordemooij commented 1 year ago

You have to invoke runQuery yourself then on the PDO instance, obtain it like this:

$pdo = R::getDatabaseAdapter()->getDatabase()->getPDO();

https://redbeanphp.com/api/classes/RedBeanPHP.Driver.RPDO.html#method_getPDO

I think that should work?

marios88 commented 1 year ago

Yea runQuery with noFetch could work, its protected but thats ok, i already inject an extended RPDO

columnCount will allways be 0 on inserts, correct? https://github.com/gabordemooij/redbean/blob/c706a13cd66c5a769b77e12d34b8e74bc3b9cfe0/RedBeanPHP/Driver/RPDO.php#L184

So this should be outside the if columnCount https://github.com/gabordemooij/redbean/blob/c706a13cd66c5a769b77e12d34b8e74bc3b9cfe0/RedBeanPHP/Driver/RPDO.php#L186

gabordemooij commented 1 year ago

Fixed https://github.com/gabordemooij/redbean/commit/184954ff320b6d8e48ee40b878b88c7bac387a52