简体   繁体   中英

MySQL returning an empty result set

I tried doing this in PHP but I got 0 rows returned all the time. Then after some time searching around on StackOverflow, I saw a tip to try doing it in SQL first to see if the results are returned properly.

I tried to do it in SQL and it's returning an empty result set all the time, even tho the values are there.

SQL

SELECT * FROM `serials_table` WHERE `ser_key`='ABCD-EFGH-IJKL-MNOP'

PHP

$result = $link->query("SELECT * FROM serials_table WHERE ser_key='$key'");

Both are returning null value.

ser_key column is set to text type, coallition: utf8_unicode_ci, Null: No, Default: None

The serial key entry is in there and the column 'ser_key' exists as well as the table 'serials_table'. Also I directly copy-pasted the serial key from the table and placed it into the query to avoid any typos.

Did I make some errors with the table structure or something?

I have no idea what to do here, any help would be appreciated.

Try

SELECT * FROM `serials_table` WHERE TRIM(`ser_key`)='ABCD-EFGH-IJKL-MNOP'

Remove white spaces

UPDATE `serials_table` set `ser_key`= TRIM(`ser_key`);

When this works

SELECT * FROM serials_table WHERE ser_key like '%ABCD-EFGH-IJKL-MNOP%'

Then you have leading or trailing spaces in your data.

To revert that update your existing table data like this

update serials_table 
set ser_key = trim(ser_key)

After that check where you insert or update the ser_key . In that code segment check if you put only trimmed data in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM