-2
當我嘗試執行此代碼時,該網站脫機。你能幫我修復代碼嗎,因爲我無法使它工作? :(我已成功地建立了更新和插入查詢。如何使用pdo從數據庫中進行選擇
Get.php
case "callfromotherfile":
$getcat = new Test();
echo json_encode($getcat->getCategories(););
break;
test.php的
class Test
{
public function __construct()
{
$this->db = ASDatabase::getInstance();
}
public function getCategories()
{
$query = ("SELECT name FROM categories");
$statement = $this->db->prepare($query);
$statement->execute();
return $statement[];
}
}
UPDATE 如何獲取?
$.ajax({
url: 'Get.php',
action: 'callfromotherfile',
dataType: 'json',
success: function(data)
{
console.log(data);
var id = data[0];
var vname = data[1];
}
});
爲您在這裏有一個語法錯誤的一件事:'回報$語句[]'。我建議你確保你的PHP解釋器顯示錯誤。 – Gondrup
這是一個[開始閱讀的好地方](http://php.net/manual/en/book.pdo.php) – RiggsFolly