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

db "insert" operation through the orm causes app freeze

I have an app written on phalcon. The are some issues running it on the production It works fine on my local machine and development server. But every "insert" DB operation through the orm causes app freeze - no errors and the execution could not finish. "select" and "update" operations through the orm work absolutely fine. When making "insert" operation with raw query there is no problem.

DB connection :

     $di->set('db', function()use ($config) {
     return new PdoMysql(array(
        "host"     => $config->database->host,
        "username" => $config->database->username,
        "password" => $config->database->password,
        "dbname"   => $config->database->name,
        'charset'   =>'utf8'
    )); 
     });

     // inserting a row in the db: 
     $user = new Users(); 
        $user->username =  '........'; $user->password = '......';
      if (!$user->save()) {
        $msg = "Error. ";
        foreach ($user->getMessages() as $message) {
            $msg .= " " . $message . ";";
        }

        $result = array(
            "status" => $config["statuses"]["error"],
            "error_number" => "10",
            "message" => $msg
        );
        echo json_encode($result);
        return;
    }

The application freezes when it gets to the "save()". Before that everything works fine. No erros or response are returned.

The configuration on the production server is : OS: Linux Debian 3.16.7 PHP: 5.6.17 MySQL: 5.5.47 Phalcon: 2.0.9

Try to use create instead with a try / catch PDOException maybe.
Take a look at :
https://github.com/corentin-begne/phalconTool/blob/master/src/lib/api/ApiController.php
working fine for me or it could be a bad configuration in your mysql production server.

edited Feb '16

Just some thoughts:

1) try corentin-begne suggestion to try/catch the exception (if you dont have try/catch in your bootstrap file already);

2) check server's error log;

3) Perhaps your production DB user does not have Insert permissions, only read?