Hurry up!!!!!Phalcon\Mvc\Model\Query\Builder::inWhere() 502 Bad Way?

The table Modules has 3 columns.

moduleid smallint(5) auto_increment primary key
parentid smallint(5)
title varchar(50)
    $modules = $this->modelsManager
        ->createBuilder()
        ->from('Modules')
        ->inWhere('parentid',[0,1])
        ->getQuery()
        ->execute();
        var_dump($modules);

When i used inWhere() , 502 Bad Way

help plz.

centos 6.4 + php 5.4.15 + nginx + phalcon 1.1.0

the routes.php like this:

$router = new Phalcon\Mvc\Router();
$router->add(
    "/:controller/:action/:int/:params",
    array(
        'controller' => 1,
        'action'     => 2,
        'id'     => 3,
        'params' => 4
    )
);
return $router;

service.php like this:

$di->set('db', function() use ($config) {
    //$eventsManager = new \Phalcon\Events\Manager();
    //$logger = new \Phalcon\Logger\Adapter\File(__DIR__ . "/../logs/db.log");
    $connection = new DbAdapter(array(
        'host' => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname' => $config->database->dbname
    ));
    /*$eventsManager->attach('db', function($event, $connection) use ($logger) {
        if ($event->getType() == 'afterQuery') {
            $logger->log($connection->getSQLStatement(), \Phalcon\Logger::INFO);
        }
    });*/
    //$connection->setEventsManager($eventsManager);
    $connection->query("SET NAMES 'UTF8'");
    return $connection;
});

$di->set('modelsManager', function(){
      return new \Phalcon\Mvc\Model\Manager();
 });
$di->set('modelsMetadata', function() use ($config) {
    return new \Phalcon\Mvc\Model\Metadata\Memory();
}, true);

nginx.conf like this:

server {
        listen   80;
        server_name mvc.dibiao.com;
        index index.php index.html index.htm;
        set $root_path '/data/www/coremvc';
        root $root_path;
        try_files $uri $uri/ @rewrite;
        location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }
        location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index /index.php;
            include fastcgi_params;
            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
            root $root_path;
        }
    }


83.0k

I copied your code in this gist: https://gist.github.com/phalcon/5581310

It's running here: http://test.phalconphp.com/where-in.php

Can you update the code in the gist to see the problem?



7.9k
edited Oct '14
<?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>';
}

i try it but output 500 again. HTTP error 500.0 - Internal Server Error C:\php\php-cgi.exe - FastCGI exit



7.9k

work env: win7+php5.3.25 + phalcon 1.1.0 dev server: centos 6.4 php 5.3.25 + phalcon 1.1.0



83.0k

did you change something to the gist code?



7.9k

no i don't change anything. can u give me your email? i post the source package to u through mail



7.9k
edited Oct '14
<?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')
        ->getQuery()
        ->execute();

foreach ($modules as $module) {
        echo $module->parentid, ' ', $module->title, '<br>';
}

If i remove the method inWhere() ,then output is correct.

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`

When i added the method inWhere() then the iis will crash and display '500 Error`



7.9k

Maybe i use windows 7 64bit?



83.0k

please send me the code to [email protected]



7.9k

ok,thank u very much!



7.9k

i have sent a mail for u.



7.9k

IIS 502 NGINX 502 Apache is ok Why????



2.8k

To apache2.4 is success! work ent: apache2.4 php5.4.14 win7x64 phalcon 1.1.0



7.9k
edited Oct '14
<?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