We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Missing events in database?

Hi, is it possible that event afterConnect, beforeDisconnect and beforeTransaction, which are mentioned in documentation are not implemented?

I created a sqlite3 impmentation:

<?php

$di = new \Phalcon\DI\FactoryDefault();

$di->set('db', function() {
  $eventsManager = new Phalcon\Events\Manager();
  $eventsManager->attach('db', function($event, $connection) {
    echo 'Event fired: ' . $event->getType() . PHP_EOL;
  });

  $connection = new \Phalcon\Db\Adapter\Pdo\Sqlite([
    'dbname' => __DIR__ . '/db.sqlite'
  ]);

  $connection->setEventsManager($eventsManager);
  return $connection;
});

$db = $di->get('db');
$db->begin();
$db->query("SELECT * FROM test");
$db->rollback();
$db->begin();
$db->query("SELECT * FROM test");
$db->commit();
$db->close();

And it dump following:

Event fired: beginTransaction
Event fired: beforeQuery
Event fired: afterQuery
Event fired: rollbackTransaction
Event fired: beginTransaction
Event fired: beforeQuery
Event fired: afterQuery
Event fired: commitTransaction

afterConnect, beforeDisconnect and beforeTransaction are not even fired. Can you paste here a doc link?

But there is no beforeTransaction event, i can see two events afterConnect and beforeDisconnect is missing in my ex.

I confirm these events don't exists either in 1.3.4 either in 2.0.0 (cf https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/db/adapter/pdo.zep search for all "db:" text, it's all db events)/



2.4k

+1 The absence of these events is very complicated debug logging in particular with division into sessions. In 2.1.0 RC1 Still did not appear.