PHP 查询不能与 bindParam 一起工作,但查询本身可以工作

PHP query not working with bindParam but the query does work in itself

我正在尝试将信息插入 mySQL 数据库,但出现 WSOD 和此错误:

PHP Fatal error: Call to a member function bindParam() on a non-object ...

这是代码:

try {
        $conectar1 = new PDO('mysql:host='.HOST.'; dbname='.DATABASE.'; charset=utf8', USER, PASS); 

    $guardarPost = $conectar1->query("
        INSERT INTO foro 
        (userID, estadoPost, asuntoPost, postUltimo, datosPost)
        VALUES (?, ?, ?, ?, ?)
    ");
    $guardarPost->bindParam(1, $userID); <============ ERROR LINE
    $guardarPost->bindParam(2, $estadoMensaje);
    $guardarPost->bindParam(3, $asuntoPost);
    $guardarPost->bindParam(4, $fechaMensaje);
    $guardarPost->bindParam(5, $datosPost);
    $ok = $guardarPost->execute();
} catch (PDOException $e) {
    echo "Error ".$e->getMessage();
}

我尝试剥离所有内容以检查数据库连接是否正常工作,确实如此。

我已经尝试将查询手动输入到 phpMyAdmin 中以替换文本的问号,它确实有效。

哪里出了问题?

尝试print_r($conectar1->errorInfo())

也用prepare()代替query()来使用bindParam()s