2013-06-30 144 views
0

我正在使用PDO连接到MySQL数据库。我的查询运行正常,并返回结果,直到我在没有结果返回的查询结束处添加“like”为止。我发布了一个模拟查询我的问题,只有麻烦点。我在哪里错了?PDO MySQL如查询不返回值

$value = "text"; 
$stmt = $pdo->prepare('SELECT something FROM table WHERE days LIKE "%:value%"'); 
$stmt->execute(array(':value' => $value)); 

感谢您的任何建议!

+1

[我如何使用与LIKE操作预处理语句?(http://stackoverflow.com/questions/15990857/reference-frequently-asked- questions-about-pdo#15990965) – DCoder

+0

不知道我是怎么没有看到,当我搜索这... ...谢谢! – Milksnake12

回答

1

尝试

$value = "text"; 
$stmt = $pdo->prepare('SELECT something FROM table WHERE days LIKE :value'); 
$stmt->execute(array(':value' => "%".$value."%")); 

或者

$value = "%text%"; 
$stmt = $pdo->prepare('SELECT something FROM table WHERE days LIKE :value'); 
$stmt->execute(array(':value' => $value));