我有我的mysql this table。
我需要php(带有PDO语句)将返回包含电子邮件“[email protected]”的每个id。我尝试了一个LIKE语句(只获取行号):
$stmt = $pdo->prepare("SELECT * FROM market WHERE buyers LIKE :email");
$needle = '%[email protected]%';
$stmt->bindValue(':email', $needle, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo $rows;
但它不起作用。
尝试使用concat for wildchar,例如:
$stmt = $pdo->prepare("SELECT * FROM market WHERE buyers LIKE concat('%', :email, '%')");
$needle = '[email protected]';
$stmt->bindValue(':email', $needle, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $key=> $value) {
echo $value['your_column_name'].'</br>';
}