Created
December 4, 2012 17:50
-
-
Save phalcon/4206807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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