2014-01-10 51 views
-3

出於某種原因,我的查詢不起作用,但它以前做過。與PDO MySQL查詢問題

$stmt = $pdo->prepare('SELECT * FROM '.$table.' WHERE urlid = :used'); 
$stmt->execute(array(':used' => $fname)); 
$num = $stmt->rowCount(); 
if ($num == 1 OR $num > 1){ 

錯誤:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE urlid = ?' at line 1' in /Applications/XAMPP/xamppfiles/htdocs/fbc/urlid.php:100 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/fbc/urlid.php(100): PDO->prepare('SELECT * FROM ...') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/fbc/urlid.php on line 100

+1

究竟是如何不工作?發佈錯誤。 –

+0

wha在'$ fname'中? –

回答

-2

嘗試到您的SQL查詢更改爲

$stmt = $pdo->prepare("SELECT * FROM $table WHERE urlid = :used"); 

,並確保您的變量$表的定義正確