2013-06-30 169 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));