我想知道是否有辦法做到以下不會導致我錯誤。有人能夠解釋爲什麼以下是不可能的,以及我怎麼能把它關掉?PHP和PDO問題
下面是函數:
public function getTaxClass()
{
$arg = func_get_args();
$pid = array_shift($arg);
$imp = implode(',',$arg);
$stmt = _DB::init()->prepare("SELECT $imp
FROM tax_class a
INNER JOIN products_to_tax_class pa ON a.tid = pa.tid
WHERE pa.pid = ?"
);
if($stmt->execute(array($pid)))
return $stmt->fetch(PDO::FETCH_ASSOC);
}
我無法插入變量到準備好的聲明?我試圖建立其添加到準備前的字符串,但是我仍然得到以下警告:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'tid' in field list is ambiguous' in /class.php:89 Stack trace: #0 /class.php(89): PDOStatement->execute() #1 /class.php(98): _Class->getTaxClass(1, 'tid', 'name', 'rate') #2 {main} thrown in/class.php on line 89
您需要將變量綁定到語句 – Drewdin 2011-06-13 20:49:15
@Drewdin它們被'array()'內部的'$ stmt-> execute()'# – 2011-06-13 20:53:43