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

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;
        }
    }


98.9k

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

It's running here: https://test.phalcon.io/where-in.php

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



12.8k
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



12.8k

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



98.9k

did you change something to the gist code?



12.8k

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



12.8k
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`



12.8k

Maybe i use windows 7 64bit?



98.9k

please send me the code to [email protected]



12.8k

ok,thank u very much!



12.8k

i have sent a mail for u.



12.8k

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



4.5k

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



12.8k
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