2017-06-12 80 views
0

這是我的PHP代碼PDOPHP PDO預處理語句與凡在第

$stmt = $conn->prepare("SELECT * FROM TABLE 
WHERE tag1 IN ('$tag1','$tag2') $andor tag2 IN ('$tag1','$tag2 ') ORDER BY $sort DESC LIMIT $limit OFFSET $start"); 
    // Then fire it up 
    $stmt->execute(); 
    // Pick up the result as an array 
    $result = $stmt->fetchAll(); 
    // Now you run through this array in many ways, for example 

我試圖把它轉換成準備好的語句,但我真的不明白,它是如何工作的。我嘗試了很多谷歌的東西,但沒有任何工作。

+0

你可以從[準備的語句是什麼](http://php.net/manual/it/pdo.prepared-statements.php)開始。 – Federkun

+0

'IN('$ tag1','$ tag2')$ andor''$ andor'的值是多少?這看起來不像一個正確的sql –

+0

是'$ andor'列? –

回答

0
$stmt = $conn->prepare("SELECT * FROM table WHERE tag1=? OR tag1=? AND tag2=? OR tag2=? ORDER BY id DESC LIMIT 15,10"); 

$stmt->execute(array($tag1, $tag2, $tag1, $tag2)); 

$result = $stmt->fetch(PDO::FETCH_ASSOC); 

我希望它能正常工作。

+0

致命錯誤:Uncaught PDOException:SQLSTATE [42S22]:未找到列:1054 C:\ xampp \ htdocs \ website \ index中'where子句'中的未知列'City' .php:189 Stack trace:#0 C:\ xampp \ htdocs \ website \ index.php(189):PDOStatement-> execute(Array)#1 {main}拋出C:\ xampp \ htdocs \ website \ index。在線189上的php – Josh

+0

@Josh可以請你參加我上面的評論 –