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

SQLSTATE[HY000]: General error

$records = $this->db->fetchAll("UPDATE ".$table." SET views = views + 1 where id='".$itemid."'", Phalcon\Db::FETCH_ASSOC);

edited Sep '14

The SQL error means your MySQL connection was refused.

You should be using models to do this, you are all calling a fetch and doing an update,

/models/YourTable.php

<?php
class YourTable extends \Phalcon\Mvc\Model
{

    public function initialize()
    {
        $this->setSource("your_table_name");
    }
}

/controllers/YourController.php

<?php

...

public function indexAction() {

    // Find a record by the itemId (Not sure how you are getting it)
    $record = YourTable::findById($itemId);

    // Increment that record ID
    ++$record->views;

    // Save it
    $record->save();

    // To see the update:
    echo $record->views;
    die;
}