下面非常简单的脚本旨在根据GET变量返回forename和surname。
每次运行脚本时都会显示以下错误:
警告:mysqli_stmt :: bind_param():变量数与第10行mypath / names.php中预准备语句中的参数数量不匹配
我检查了SQL查询,它在SQLyog中运行得非常好。我也使用get变量调用该文件:names.php?surname = jo
<?php
ini_set("display_errors",1);
require_once('connection.php');
$db = DB::connect();
$db->select_db("mydb");
$sql = "SELECT forename,surname FROM `people` WHERE `surname` LIKE '?%' LIMIT 1";
if ($stmt = $db->prepare($sql)) {
$stmt->bind_param("s", $_GET['surname']);
$stmt->execute();
$stmt->bind_result($forename, $surname);
$stmt->fetch();
$stmt->close();
}
?>
答案 0 :(得分:1)
你应该尝试:
$sql = "SELECT forename,surname FROM `people` WHERE `surname` LIKE ? LIMIT 1";
与
$surname=$_GET['surname']."%";
$stmt->bind_param("s", $surname);