当我尝试使用 Phalcon 进行 $query->save() 时出现 SQLSTATE[HY093] 错误

ERROR SQLSTATE[HY093] when Im try to $query->save() using Phalcon

我正在尝试对数据库进行简单的更新,但出现错误,我认为这是 PDO 问题,但我找不到解决方案,我不知道还能做什么, 我用的是 Phalcon 2.0.7

错误:SQLSTATE[HY093]:参数编号无效:绑定变量的数量与标记的数量不匹配

示例 Url:http://domain.com/controller/hide/8

在我的控制器上:

public function hideAction($id) {
    $query = Table::findFirst($id);
    $query->active = 0;
    $query->save();
}

但我也试试这个:

public function hideAction($id) {
    $query = Table::findFirst($id);
    $query->save([
        'active' => 0
    ]);
}

在我的模型上:

use Phalcon\Mvc\Model;

class Table extends Model {

   public $id;

   public $active;

   public $title;

   public function initialize() {

   }

   public function getSource() {
      return 'table_sample';
   }
}

我的数据库连接调度程序服务:

$di->set('db', function() use ($config) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(
        array(
        "host" => $config->db->host,
        "username" => $config->db->username,
        "password" => $config->db->password,
        "dbname" => $config->db->dbname
        )
    );
});

如您所见,这是一个简单的更新,可能我遗漏了什么

您必须使用此 findFirst 样式:
$query = Table::findFirstById($id);
或者
如果你想使用你的方法,你必须像这样编写条件(where)语句:
$query = Table::findFirst("id = $id");

试用并更新记录。