"having issue with matching rows in the database using pdo" Code Answer

4

problems caused by the data

most likely there are some converted or non-printable characters in the input data (or database). for example, there could be a linefeed character or a peculiarly encoded symbol, or some characters such as < and > converted into html entities. as a result, the query contains <abc@abcs.com> will never match a text &lt;abc@abcs.com&gt;.

the problem is, this is only a guess, and nobody can tell you what the actual issue is, because it is your database, your input data and only you can find the issue.

i wrote an article that explains how to debug your pdo issues.

to debug a particular issue, you need

  • make sure the full error reporting is enabled for both pdo and php. it really helps, showing you occasional typographic errors, spelling errors and the such
  • scrutinize both the data in the database and the input to find the difference. bin2hex() function would help, revealing all non-printable and converted characters, in both database and the input.

problems caused by the connection credentials

another frequent issue is when you have several databases and connect to the wrong one that doesn't have the data requested. this issue is similar to this one, so just follow the same routine, only checking not the list of tables but the data rows.

an irrelevant but important note

on a side note, but very important nevertheless: your prepared statement is a cargo cult code that protects nothing. here is how it must be:

$sql = 'select count(*) from inbox where uid = ? and from_email = ?'; 
$result = $link->prepare($sql); 
$result->execute([$email_number,$email_f]); 
$number_of_rows = $result->fetchcolumn(); 
By Piotr Dawidiuk on July 12 2022

Answers related to “having issue with matching rows in the database using pdo”

Only authorized users can answer the Search term. Please sign in first, or register a free account.