Lepuz
Lepuz

Reputation: 9

Select pdo cant find the symbol like & '

PDO can't find the & symbol. My data is:

Fast & Furious

My code is:

$sec = $db->prepare("Select * from filmler where film_ad = ?");
$sec->bindParam(1, $needle, PDO::PARAM_STR)

rowCount resulting 0 but $needle is equal to "Fast & Furious". I mean I'm actually looking for "Fast & Furious".

Upvotes: 0

Views: 86

Answers (1)

N'Bayramberdiyev
N'Bayramberdiyev

Reputation: 3620

Execute the prepared statement after binding variables.

$needle = 'Fast & Furious';

If you want to find exactly the same value as $needle, try this:

$sec = $db->prepare('SELECT * FROM filmler WHERE film_ad = ?');
$sec->bindParam(1, $needle, PDO::PARAM_STR);
$sec->execute();

var_dump($sec->rowCount());

Or:

$sec = $db->prepare('SELECT * FROM filmler WHERE film_ad = ?');
$sec->execute([$needle]);

var_dump($sec->rowCount());

If you want to use LIKE operator with % wildcard, then try this:

$needle = "%{$needle}%";

$sec = $db->prepare('SELECT * FROM filmler WHERE film_ad LIKE ?');
$sec->bindParam(1, $needle, PDO::PARAM_STR);
$sec->execute();

var_dump($sec->rowCount());

Or:

$sec = $db->prepare('SELECT * FROM filmler WHERE film_ad LIKE CONCAT("%", ?, "%")');
$sec->execute([$needle]);

var_dump($sec->rowCount());

Upvotes: -1

Related Questions