<?php $di = new \Phalcon\DI(); $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array( 'hostname' => 'localhost', 'username' => 'root', 'password' => '123456', 'dbname' => 'coremvc' )); $eventsManager = new Phalcon\Events\Manager();
//Listen all the database events $eventsManager->attach('db', function($event, $connection){ if ($event->getType() == 'beforeQuery') { $sqlVariables = $connection->getSqlVariables(); if (count($sqlVariables)) { echo $connection->getSqlStatement(), ' [', join(', ', $sqlVariables), ']<br>'; } else { echo $connection->getSqlStatement(), '<br>'; } } });
//Assign the eventsManager to the db adapter instance $db->setEventsManager($eventsManager);
$di['db'] = $db; $di['modelsManager'] = new Phalcon\Mvc\Model\Manager(); $di['modelsMetadata'] = new Phalcon\Mvc\Model\MetaData\Memory();
//Define the class class Modules extends Phalcon\Mvc\Model {
} $modules = $di['modelsManager'] ->createBuilder() ->from('Modules') ->inWhere('moduleid',array(1,2)) ->getQuery() ->execute();
foreach ($modules as $module) { echo $module->parentid, ' ', $module->title, '<br>'; / This row ouput nothing / }
The table Modules
have 2 rows.
moduleid parentid title
1 0 System
2 1 Config
but output is empty
output is empty
SELECT IF(COUNT(*)>0, 1 , 0) FROM INFORMATION_SCHEMA
.TABLES
WHERE TABLE_NAME
='modules'
DESCRIBE modules
SELECT modules
.moduleid
, modules
.parentid
, modules
.title
FROM modules
WHERE modules
.moduleid
IN (:phi0, :phi1) [1, 2]
Apache 2.4.4 + php 5.3.25 + phalcon 1.1.0
and when i used nginx, the method named with inWhere()
will be crash, FASTCGI ERROR