<?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
答案 0 :(得分:2)
您传递的参数无效。
authorid:
不存在。 :
应该在
$parameters = [':joketext'=>$joketext,':authorid'=>$authorid];