PHP检查mysql数据库是否包含字符串中的字符串

So I have a database column where it has like past usernames.

This is what the row would look like if it had info.

bill, joe, ryan

What I am trying to do is check ever single row and check if like any of them contain joe. I have one possible theory on how to do it but what I fear is say someones past username is this:

billjoe

Im afraid it would think it exists in database because of that bill in it i would want it to ignore it if its not exactly bill.

Whats confusing is it could have for example 3 names in 1 string seperated by commas.

My theory on how to do it is like this:

$stmt = $db->prepare("SELECT * FROM users WHERE pastusernames LIKE :pastusernames");
$stmt->execute(array(':pastusernames' => "%bill%"));

But that may even be totally wrong. So is there anyway to do this correctly?

Not sure how write in PHP. But the sql should look like this:

SELECT * 
FROM users 
WHERE ', ' + pastusernames + ',' LIKE '%, bill,%'

adding the , you make sure the match the whole thing and not just a part

I am not sure but may be below query may be work for you

$stmt = $db->prepare("SELECT * FROM users WHERE pastusernames LIKE :pastusernames");
$stmt->execute(array(':pastusernames' => "bill"));