gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:04:52 25 4
gpt4 key购买 nike

我的mysql中有this table .

我需要 php(带有 PDO 语句)返回包含电子邮件“mrgamer751p@gmail.com”的每个 id。我尝试使用 LIKE 语句(仅获取行数):

$stmt = $pdo->prepare("SELECT * FROM market WHERE buyers LIKE :email");
$needle = '%mrgamer751p@gmail.com%';
$stmt->bindValue(':email', $needle, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo $rows;

但是这不起作用。

最佳答案

尝试使用 concat 来表示通配符,例如:

 $stmt = $pdo->prepare("SELECT * FROM market WHERE buyers LIKE concat('%', :email, '%')"); 
$needle = 'mrgamer751p@gmail.com';
$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>';
}

关于php - 获取字符串包含 php pdo 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47970195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com