Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFR - Allow SQL Logging & Debugging options #42

Open
amsharma9 opened this issue Jun 9, 2016 · 1 comment
Open

NFR - Allow SQL Logging & Debugging options #42

amsharma9 opened this issue Jun 9, 2016 · 1 comment

Comments

@amsharma9
Copy link

Hello,

I wanted to request you to add the facility to log SQL statements in your framework. See this:
https://docs.phalconphp.com/en/latest/reference/models.html#logging-low-level-sql-statements

I have this in my Base App based config.ini

[app]
name = "base-app"
...
enableDebugging = 1
enableDblogging = 0

Or we can use just Debug & DBLog.

Kindly also provide Debugging boolean for code. We can place our echos, var_dump, \Phalcon\Debug\Dump calls in if (enableDebugging) { ...

Thanks
Amal

@mruz
Copy link
Owner

mruz commented Jun 9, 2016

Hi Amal,
There is a Listener.php in the app/common/extension directory, so you can attach it to Events Manager:

$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('db', new \Baseapp\Extension\Listener());
$this->db->setEventsManager($eventsManager);

and run some query to debug:

$query = $this->db->convertBoundParams('SELECT * FROM `users` WHERE `user_id` = :user_id:', array(':user_id' => 1));
$user = $this->db->fetchAll($query['sql'], \Phalcon\Db::FETCH_ASSOC, $query['params']);

or you can add it in the Bootstrap if the env is development:

protected function db()
{
    $config = $this->_config;

    $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
        "host" => $config->database->host,
        "username" => $config->database->username,
        "password" => $config->database->password,
        "dbname" => $config->database->dbname,
        "options" => array(
            \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
        )
    ));

    if ($config->app->env == "development") {
        $eventsManager = new \Phalcon\Events\Manager();
        $eventsManager->attach('db', new \Baseapp\Extension\Listener());
        $db->setEventsManager($eventsManager);
    }

    $this->_di->set('db', $db);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants