当我移除firstcomm Like %?%
时,它可以正常工作。当我将其保留时,它无法返回结果(尽管脚本中没有实际错误)。是的,firstcomm
是我数据库的一部分。那么为什么呢?我在做%?%
错了吗?
$dbh = new PDO(...);
$sql = 'SELECT ... FROM ... WHERE firstcomm LIKE %?% AND ...';
$params = array( $qu, ... );
$q = $dbh->prepare( $sql );
$q->execute( $params );
$doc = new DOMDocument();
更新:这也失败了......
$dbh = new PDO(...);
$sql = 'SELECT ... FROM ... WHERE firstcomm LIKE ? AND ...';
$params = array( $qu, ... );
$q = $dbh->prepare( $sql );
$q->execute( $params );
$doc = new DOMDocument();
答案 0 :(得分:2)
试试这个
$sql = "SELECT ... FROM ... WHERE firstcomm LIKE '%?%' AND ...";
答案 1 :(得分:1)
$sql = 'SELECT ... FROM ... WHERE firstcomm LIKE ? AND ...';
$like = '%?%';
$stmt = $connection->prepare($sql);
$stmt->bind_param('s', $like);
$stmt->execute();