First of all, you have to embrace the fact: if your query found no rows, it means there is no match, even if you can swear the data is all right. So you need to investigate, why there is no match.
Problems caused by SQL errors
Make sure that your query actually runs without errors, as "no result" could mean an error in the query. Refer to these answers for the details: pdo and mysqli.
In case the error says "no such table/database", see the "connection credentials" case below.
Problems caused by the condition
Check your conditions. There are mutual exclusive conditions, such as WHERE col=1 AND col=2. It will never return any rows. Try to simplify the condition until it starts returning some rows, and then refine the conditions to get the desired result. Note that with prepared statements, you cannot bind an arbitrary query part, but only a distinct data literal. Table and column names also cannot be bound.
But all right, there are no errors, all conditions are correct, and you can swear the table contains data to match your query. Still, there are some pitfalls:
Problems caused by the data
First of all, in case a variable involved, make sure it exists and actually contains some value.
Then check the value itself. There could be some converted or non-printable characters in the input data (or database). For example a stray space or a linefeed character; or a peculiarly encoded symbol; or some characters such as < and > converted into HTML entities. As a result, the query contains <[email protected]> will never match a text <[email protected]>. For a quick check you can use rawurlencode() function, it will convert all non-latin characters into codes, thus making them visible.
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 in more detail.
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 such
- scrutinize both the data in the database and the input to find the difference.
urlencode() 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.
Problems caused by character set/encoding
It's a rare case, but just to to be sure, follow the checklist from this great answer