版本: v2.3.0
get
從資料表中取得單筆記錄。
get($table, $columns, $where)
table [string]
要查詢的資料表名稱。
columns [string/array]
要回傳的欄位。
where [array] (可選)
用於篩選結果集的 WHERE 條件。
get($table, $join, $columns, $where)
table [string]
要查詢的資料表名稱。
join [array]
用於關聯相關資料表的 JOIN 定義;如果不需要 JOIN,可省略此參數。
columns [string/array]
要回傳的欄位。
where [array] (可選)
用於篩選結果集的 WHERE 條件。
回傳值
[mixed] 回傳首筆符合條件的記錄;如果只查詢單一欄位,則回傳純量值,否則回傳關聯陣列。
$email = $database->get("account", "email", [
"user_id" => 1234
]);
// 範例結果:
// "foo@bar.com"
$profile = $database->get("account", [
"email",
"gender",
"location"
], [
"user_id" => 1234
]);
// 範例結果:
// array(
// "email" => "foo@bar.com",
// "gender" => "female",
// "location" => "earth"
// )
$data = $database->get("post", [
"[>]account" => "user_id"
], [
"post.content",
"account.user_name",
"account.location"
], [
"ORDER" => "post.rate"
]);
// 範例結果:
// array(
// "content" => "A new day",
// "user_name" => "foo",
// "location" => "earth"
// )