版本: 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"
// )