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

getLastSql

This is my code: $data = Users::find(array( 'username = :username: and password = :password:', 'bind' => $post ));

I want just after the SQL;

I know print_r ($data) can see SQL but that is not resolved, could you tell me is there a better way?



20.5k
edited Sep '14
$di->set('profiler', function() {
    return new \Phalcon\Db\Profiler();
    }, true);

    $di->set('db', function() use ($config,$di) {

    $eventsManager = new \Phalcon\Events\Manager();

    $profiler = $di->getProfiler();

    $eventsManager->attach('db', function($event, $connection) use($profiler) {
        if ($event->getType() == 'beforQuery') {
        $profiler->startProfile($connection->getSQLStatement());
        }

        if ($event->getType() == 'afterQuery') {
        $profiler->stopProfile();
        }
    });

    $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
        "host" => $config->database->host,
        "username" => $config->database->username,
        "password" => $config->database->password,
        "dbname" => $config->database->name,
        'charset' => 'utf8'
    ));

    $connection->setEventsManager($eventsManager);

    return $connection;
    });

CGI/FastCGI stop working

This is what problem, my environment is nginx phpstudy use



98.9k

What do you mean by "CGI/FastCGI stop working"?



20.5k

Yes, after I modify about database configuration there, as long as there is a database access operation method is the pop-up CGI stop working, and do not have a database query access method, there is no proble



20.5k

What do you mean by "CGI/FastCGI stop working"? SELECT users.id, users.nickname, users.username, users.password, users.regional_id, users.community_id, users.created_at FROM users WHERE users.username = :username AND users.password = :password LIMIT 1

Thanks, got it, but it is not what I want, because I can't see the value of the username and password, in some cases, I think it is necessary according to the correct value to judge whether the SQL execution