Jump to content

executing mysql LIKE query


sax

Recommended Posts

Hy
I'm trying to execute this query

$stmt = $mysqli->prepare("SELECT streamer,content,provider
      FROM  evento,canali
      WHERE canali.id=evento.idcanale
      AND evento.titolo LIKE '%?%' OR evento.sottotitolo LIKE '%?%'
      AND evento.datainizio=2013-02-21;");
$stmt->bind_param('ss',$tok,$tok);
$stmt->execute();
$stmt->close();
but I get this error Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement. 
but to me it seems like the number are the same,  you can see how I prepared the statement with 2 arguments to define, and then I passe 2 arguments to add_param, what I'm getting wrong?

 

some has some ideas?
thanks
daniele New php-forum User
rank_1.png   Posts: 2 Joined: Fri May 03, 2013 6:48 pm
  •  
 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/277647-executing-mysql-like-query/
Share on other sites

I am so not inclined to help you since the only effort you've shown here is that you can copy/paste entire posts from another forum. You didn't even bother to copy only the text.

 

But it's a very easy answer so I will anyway.

 

Bound variables don't work like simple string replacements. If you want to LIKE a field against a bound string then the string has to be the entire expression - %s and all.

$tok = "%" . $tok . "%";
AND evento.titolo LIKE ? OR evento.sottotitolo LIKE ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.