开发者

Mysql Like bind_param() on a non-object

    $id='gsf';
$stmt=$mysqli->prepare('SELECT `title` FROM `post` WHERE (`content` LIKE `%?%`) and accepted=0 order by count desc Limit 0,5');
      $stmt->bind_param('s',$id);
      $stmt->execute();
      $stmt->bind_result($title);
      while($stmt->fetch();)
    {
      echo $title."<br>";开发者_StackOverflow中文版         
      }
      $stmt->close();
      $mysqli->close();

This is a Php Snippet hen i execute it i get this error Call to a member function bind_param() on a non-object

what am i missing out??


Try this:

$stmt=$mysqli->prepare('SELECT `title` FROM `post` WHERE (`content` LIKE ?) and accepted=0 order by count desc Limit 0,5');

$stmt->bind_param('s',$id);

$id = '%gsf%'; //The **%** go here

$stmt->execute();
$stmt->bind_result($title);

while( $stmt->fetch() ) {
      echo $title."<br>";         
}

$stmt->close();
$mysqli->close();


Your SQL is erronous, thus $stmt is not a prepared statement. Analyze the content of $mysqli->errno and $mysqli->error to find the problem in your SQL query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜