【问题标题】:Error in mysqli prepare statementmysqli准备语句中的错误
【发布时间】:2014-08-01 07:22:41
【问题描述】:
$client = $db -> prepare('SELECT CLIENT_ID, CLIENT_NAME FROM client WHERE CLIENT_NAME LIKE "%?%"');
    $query = $_GET['query'];
    $client -> bind_param('s', $query);
    $client -> execute();
    $client -> bind_result($client_id, $client_name);
    while($client -> fetch()){
        $d['suggestions']['value'] = $client_name;
        $d['suggestions']['data'] = $client_id;
    }
    $client -> free_result();

我在上述声明中收到以下错误。看不出是什么导致了错误。

<b>Warning</b>:  mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in <b>getclient.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined index: callback in <b>getclient.php</b> on line <b>24</b>

现在我有另一个错误消息:

Call to a member function bind_param() on a non-object

【问题讨论】:

标签: php mysql mysqli prepared-statement


【解决方案1】:

关于百分比,你不能像那样做 LIKE 语句。

$client = $db -> prepare('SELECT CLIENT_ID, CLIENT_NAME FROM client WHERE CLIENT_NAME LIKE ?');
$query = $_GET['query'];
$client -> bind_param('s', "%{$query}%");
$client -> execute();
$client -> bind_result($client_id, $client_name);
while($client -> fetch()){
    $d['suggestions']['value'] = $client_name;
    $d['suggestions']['data'] = $client_id;
}
$client -> free_result();`

【讨论】:

    猜你喜欢
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2011-02-02
    相关资源
    最近更新 更多