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

Upgrade from Legacy SQLSTATE[HY000]: General error

Hi there, I upgraded from legacy and so far most of the app seems to work without any issues. But when opening one of the pages, I get a "SQLSTATE[HY000]: General error" without any further information.

The odd thing is, one in 20 times, this page loads.

I'm not performing any fancy qureies and am only reading. Any idea what could be the cause of this?



5.7k

ahh I found the cause. I had a method call which executes a sql query.

hmm, how should I do this with the latest phalcon version?

    public static function markTicketRead($user, $ticket)
    {
        $user   = (int)$user;
        $ticket = (int)$ticket;

        $sql = "INSERT INTO ticket_read (user_id, ticket_id, ticket_read_at)
            VALUES (" . $user . ", " . $ticket . ", NOW())
            ON DUPLICATE KEY UPDATE
            ticket_read_at = NOW()";

        $ticketRead = new TicketRead();

        return new Resultset(null, $ticketRead, $ticketRead->getReadConnection()->query($sql, null));
    }


3.4k
edited Jun '17

It's difficult to give some blind response.

what IDE do you use ? Try to addon debug option on.

You can try to see with xdebug on phpstorm free trial https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html. It worked great for debugging easily.



5.7k

i'm looking for a way to run a custom query with the latest phalcon, do you know how to?



5.7k

According to the latest doc, I'm doing it right: https://docs.phalcon.io/en/3.2/db-phql#raw-sql

First - use binding Second - SQLSTATE[HY000]: General error this is pdo error, not phalcon itself, it might be caused by phalcon but this just doesn't tell anything.



3.4k
edited Jun '17

if you need this only in insert, you can change your table structure accepting your datetime to be null with current_datetime default value.

https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html



5.7k

I need to work with on duplicate key update. Else I risk inconsistencies.

if you need this only in insert, you can change your table structure accepting your datetime to be null with current_datetime default value.

https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html



5.7k

Tried that, its not the cause.

First - use binding Second - SQLSTATE[HY000]: General error this is pdo error, not phalcon itself, it might be caused by phalcon but this just doesn't tell anything.

Check it with plain pdo - if the same problem will happen.



5.7k

Running it directly works just fine:

        $di             = \Phalcon\DI::getDefault();
        $db             = $di['db'];
        $data           = $db->query( $sql );
        $results        = $data->execute();

Well actually return new Resultset(null, $ticketRead, $ticketRead->getReadConnection()->query($sql, null)); uses exactly some service and same code, so im not sure what's a problem. Also:

  • use $db->query method if query returns any records
  • use $db->execute method if query doesn't return any records

Doing $data->execute() will actually execute same query again i think