mysqli_stmt :: bind_param():变量数量与php中预准备语句中的参数数量不匹配

时间:2017-10-20 03:29:54

标签: php

DbOperations.php

    public function getGender($id)
    {
        $stmt = $this->con->prepare("select gender, dob_year from table_user where id = '$id'");
        $stmt->bind_param("ss", $gender, $dob_year);
        $stmt->execute();

        return $stmt->get_result()->fetch_assoc();
    }

data.php

<?php
require_once 'database_config/DbOperations.php';

$response = array();

$id = $_POST['id'];

$db = new DbOperations();

$user = $db->getGender($id);

$response['gender'] = $user['gender'];
$response['dob_year'] = $user['dob_year'];

echo json_encode($response);
?>

嗨,我正试图从&#34; id&#34;中获取dob_year和性别信息。输入。但它会发出警告

mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

可能是什么原因?

1 个答案:

答案 0 :(得分:0)

应该是这样的

public function getGender($id)
    {
        $stmt = $this->con->prepare("select gender, dob_year from table_user where id = ?");
        $stmt->bind_param("s",$id);
        $stmt->execute();

        return $stmt->get_result()->fetch_assoc();
    }