Skip to content

Instantly share code, notes, and snippets.

@phalcon
Created December 4, 2012 17:50
Show Gist options
  • Save phalcon/4206807 to your computer and use it in GitHub Desktop.
Save phalcon/4206807 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
$di = new Phalcon\DI();
$di->set('modelsManager', function() {
return new Phalcon\Mvc\Model\Manager();
}, true);
$di->set('modelsMetadata', function() {
return new Phalcon\Mvc\Model\MetaData\Memory();
}, true);
$di->set('db', function() {
$connection = new Phalcon\Db\Adapter\Pdo\Mysql(array(
'host' => 'localhost',
'username' => 'some-user',
'password' => 'some-pass',
'dbname' => 'invo'
));
$eventsManager = new Phalcon\Events\Manager();
$eventsManager->attach('db', function($event, $connection){
if ($event->getType() == 'beforeQuery') {
echo $connection->getSqlStatement(), ' ';
$variables = $connection->getSqlVariables();
if ($variables) {
echo '[', join(', ', $variables), ']';
}
echo "<br>\n";
}
});
$connection->setEventsManager($eventsManager);
return $connection;
}, true);
class Products extends Phalcon\Mvc\Model
{
}
$di->getModelsManager()->executeQuery("UPDATE Products SET price = ?0 WHERE id > ?1", array(10, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment