喜欢命令不在mysql中工作

时间:2014-02-14 09:18:46

标签: php mysqli sql-like

当我移除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();

2 个答案:

答案 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();