我正在使用函數來檢索基於兩個參數$request
和$id
的產品信息。處理請求並返回正確的數據庫字段以在查詢中使用。但是信息沒有被返回,但是作爲字符串的是$request
。值不返回
public function productInformation($request,$id) {
switch($request) {
case "id":
$request = "id";
break;
case "desc":
$request = "description";
break;
case "slug":
$request = "slug";
break;
case "parent":
$request = "parent";
break;
case "thumb":
$request = "thumb_url";
break;
case "image":
$request = "image_url";
break;
case "visible":
$request = "visibility";
break;
case "time":
$request = "stamp";
break;
}
$connect = new dbconnect;
$connect->query("SELECT :request FROM products WHERE id = :id");
$connect->bind(":request",$request);
$connect->bind(":id",$id);
$query = $connect->single();
return $query[$request];
}
所以,如果$request = "desc"
,return $query[$request]
將返回description
作爲一個字符串?我打電話給正確的數組鍵,但我不太確定問題是什麼?