数据库错误:SQLSTATE [HY093]

时间:2018-03-19 03:32:09

标签: php mysql

<?php

include_once __DIR__ . '/../includes/DatabaseConnection.php';
include_once __DIR__ . '/../includes/totalJokes.php';

function query($pdo,$sql,$parameters=[]){
    $query = $pdo->prepare($sql);
    foreach($parameters as $name=>$value){
        $query->bindValue($name,$value);
    }
    $query->execute();
    return $query;
}
function getJoke($pdo,$id){

    $query = 'SELECT * FROM `joke` WHERE `id`= :id';
    $parameters = [':id'=>$id];
    $row = query($pdo,$query,$parameters);
    return $row->fetch();
}

function insertJoke($pdo,$joketext,$authorid){
    $parameters = [':joketext'=>$joketext,'authorid:'=>$authorid];
    $query = 'INSERT INTO `joke` SET `joketext`= :joketext,
    `jokedate` = CURDATE(), `authorid`= :authorid';
    query($pdo,$query,$parameters);
}
function updateJoke($pdo,$id,$joketext,$authorid){
    $parameters = [':authorid'=>$authorid, ':joketext'=> $joketext, ':id'=>$id];
    $query = 'UPDATE `joke` SET `authorid`= :authorid,`joketext`= :joketext WHERE `id`= :id';
    query($pdo,$query,$parameters);

}
?>

调用函数insertJoke()时出现以下错误。

  

数据库错误:SQLSTATE [HY093]:参数号无效:参数   未定义于:   /home/vagrant/Code/Project/includes/DatabaseFunctions.php11

1 个答案:

答案 0 :(得分:2)

您传递的参数无效。

authorid:不存在。 :应该在

之后

$parameters = [':joketext'=>$joketext,':authorid'=>$authorid];