Please see the bottom of this post for newest information and current status
Following advise from posts like this one: Using wildcards in prepared statement - MySQLi
I have my statement set up and it works with no errors. But it does not return the correct data.
My select statement has this for the WHERE:
WHERE `Name` LIKE ? order by `Name`
My string to set up the binding, and then the actual binding.
$whatToBind = '%'. $whatName .'%';
$stmt = $mysqli->prepare($selectStr);
$stmt->bind_param('s', $whatToBind);
$stmt->execute();
When I get my return, it will completely miss records that it should match. Like, if I send in "Ken L", I get back records for "Ken Linton" but not "Ken Lawton". If I put in "Lawton", I get no return at all.
This is typical behavior across the board. If I search a phone number field, I get returns on "658", but no returns on "609-658".
If anyone can clue me in on what I'm missing, that would be great.
Example returns that show the exact examples I'm referring to:
Empty, though it shouldn't be:
Returns all, including the record that should have been there with the other 2:
Questions to answer: Some further things to check:
Check the MySQL / PHP interaction character set is set correctly, typically with: $mysqli->set_charset("utf8mb4"); right after database connection is established.
It is set to utf8. Although it behaved the same before this was set.
Can you show any output from $mysqli->error ?
There are no errors. Just incomplete returns
Can you show us your whole SQL query?
It's included in the screen grabs. Although, that's just a plain string. And it doesn't account for what the prepared statement looks like.
Can you show the Collation / MySQL structure of the Names column?
It is all utf8 as per GoDaddy's phpMyAdmin
Can you show what the value of $whatName is right before binding?
It's at the top of the screen grab. It's echoed back to show it before anything else happens.
At this point I am thinking that the issue lies in what happens when the field I'm searching has a space or other character that is not a letter. Not what I'm passing in exactly. But more like, once the statement is prepared what is prepared is not matching what is in the field it is searching. This doesn't happen when you search the field prior to where the space exists. This is why "Ken" works 100% of the time, but "Lawton" fails completely. It's after the space.
I have tried all manner of converting the encoding type. And I have tried the various methods of concatenating the string. The results I'm getting are either no better, of completely breaking it.
Still 21 hours left on this bounty, if anyone has any more ideas. At this point, I'd be more happy to award 25 each to the two dudes that provided the best information. Seems unfair to reward one and not the other.