executing mysql LIKE query

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

daniele
New php-forum User
New php-forum User
Posts: 2
Joined: Fri May 03, 2013 9:48 am

executing mysql LIKE query

Postby daniele » Fri May 03, 2013 9:52 am

Hy
I'm trying to execute this query

Code: Select all

$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
some has some ideas?
thanks

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: executing mysql LIKE query

Postby seandisanti » Fri May 03, 2013 12:21 pm

The error means that you prepared the statement to expect a specific number of arguments, but you then executed it with fewer.

daniele
New php-forum User
New php-forum User
Posts: 2
Joined: Fri May 03, 2013 9:48 am

Re: executing mysql LIKE query

Postby daniele » Sat May 04, 2013 4:08 am

yes, but 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?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: executing mysql LIKE query

Postby seandisanti » Fri May 10, 2013 10:25 am

you have to use full variable names to use 'like'. see here: http://www.dreamincode.net/forums/topic ... with-like/

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: executing mysql LIKE query

Postby seandisanti » Fri May 10, 2013 10:27 am

of course you could just use PDO, it's better; just saying


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests