我想我的代碼從mysql_query
轉換爲PDO
,並使用此功能PDO綁定帕拉姆麻煩
function label_for_field($field_name, $table_name) {
$table = array();
// Bind variables to parameters
$param_array = array(':bundle' => $table_name, ':field_name' => $field_name);
// Prepare Query Statement
$query = "SELECT data FROM field_config_instance WHERE bundle = :bundle AND field_name = :field_name";
$STH = $DBH -> prepare($query);
// Execute
$STH -> execute($param_array);
// Set the fetch mode
$STH -> setFetchMode(PDO::FETCH_OBJ);
while ($row = $STH -> fetch()) {
$info = unserialize($row -> data);
$table[] = $info['label'];
}
return $table[0];
}
開始,我嘗試只是輸出它,看它是否工作
include_once ("includes/connect.php");
include ("includes/functions.php");
echo label_for_field("field_account_number", "account_table");
而這裏的connect.php
// Include Constants
require_once ("constants.php");
//Establish Connection
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
}
catch (PDOException $e) {
echo $e -> getMessage();
}
我不知道這是否是因爲我綁定的參數錯了,它只是給了我一個服務器錯誤頁面
「服務器錯誤。而檢索......」
在此先感謝
錯誤是什麼? – feeela 2012-07-31 15:39:20
@feeela我剛剛編輯了問題並添加了有關錯誤的其他信息 – lusketeer 2012-07-31 15:45:49
不,您沒有。參考你的服務器'error.log'來查看實際的錯誤... – feeela 2012-07-31 16:10:17