Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的查询
SELECT * FROM products WHERE status="active" AND product_name LIKE "%sony\'s%"
但它不返回结果,而在产品表中我有一个名为“Sony\'s”的产品
如果有人有,请给我解决方案。
谢谢
使用PDO或MYSQLI
使用 PDO 扩展的示例:
<?php $name = "active"; $value = "%" + $product_name + "%"; $stmt = $dbh->prepare("SELECT * FROM products WHERE status = ? AND product_name LIKE ?"); $stmt->bindParam(1, $name); $stmt->bindParam(2, $value); $stmt->execute(); ?>
这将允许您使用带单引号的记录。
将“%sony\'s%”替换为'%sony''s%'
'%sony''s%'
例如
SELECT * FROM products WHERE status="active" AND product_name LIKE '%sony''s%'