0

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".

N'Bayramberdiyev
  • 5,936
  • 7
  • 27
  • 47
Lepuz
  • 9
  • 1
  • 2
  • Please add a little more detail. It is far from clear what your problem actually is – RiggsFolly Jan 08 '20 at 18:37
  • Change filter: **where film_ad LIKE ?** and use % for $needle: **$sec->bindParam(1, "%$needle%",PDO::PARAM_STR);** – Triby Jan 08 '20 at 18:39
  • Show the code where you actually execute the statement, fetch the result, and check/dump the result. – Patrick Q Jan 08 '20 at 18:57
  • Maybe the data in database is HTML encoded. – Dharman Jan 08 '20 at 20:13
  • Then the data in your database isn't what you think it is. There might be stray whitespace, unprintable characters, or the data is encoded differently than you think it is. Run `SELECT HEX(film_ad) WHERE id = ?` or similar and post the results and we can tell you what it actually is – Sammitch Jan 09 '20 at 02:03

1 Answers1

1

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());
N'Bayramberdiyev
  • 5,936
  • 7
  • 27
  • 47