0

我对 PHP 比较陌生,正在学习绑定。我收到绑定错误:

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

if( isset( $_GET['last_name'],$_GET['id'] )) {
    $last_name = trim($_GET['last_name']);
    $id = trim($_GET['id']);
    $people = $db->prepare( "select firstName, last_name, id from people where last_name = ? or id >= ?");
    $people->bind_param('ssi', $first_name, $last, $id);
    $people->execute();
    $people->bind_result( $first_name, $last, $id );

我在 bind_param 行上遇到错误。我有“ssi”,虽然我的意思是字符串、字符串、整数,并且我有三个变量。在我的选择中,我有三个正确命名的字段。如果我更改为“si”并删除任一名称字段,它工作正常。所以我很困惑为什么添加第二个字符串不起作用。

4

1 回答 1

0

You have two question marks in that clause:

"select firstName, last_name, id from people where last_name = ? or id >= ?"

(Pay attention to camelCases firstName param and underscored rest of params, it is good practice to stick with one naming convention to avoid problems)

which means You want to bind 2 params, but in next line You are trying to put 3 params

$people->bind_param('ssi', $first_name, $last_name, $id)

Delete $first_name variable from bind_param and 's' from types.

This should look like this:

$people->bind_param('si', $last_name, $id)

NOTE: Your $last and $first_name variables are undefined.

于 2014-06-28T13:40:18.680 回答