获取一行包含php pdo的字符串

问题描述 投票:0回答:1

我有我的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;

但它不起作用。

php mysql string pdo
1个回答
0
投票

尝试使用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>';
}
© www.soinside.com 2019 - 2024. All rights reserved.