From 268d8cb18ebec7291dde6d40d99a229802d5d2c2 Mon Sep 17 00:00:00 2001 From: Mathilde Date: Thu, 12 Dec 2019 15:40:46 +0100 Subject: [PATCH 1/2] Update database.md Add new informations and examples to the database query --- content/developer/framework/database.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/content/developer/framework/database.md b/content/developer/framework/database.md index 99e12488..4498cdb6 100644 --- a/content/developer/framework/database.md +++ b/content/developer/framework/database.md @@ -31,6 +31,24 @@ Gdn::sql() ->get(); ``` +If you want to retrieve the request result as an array of associative arrays, you can use the `resultArray()` after the `get()` method +``` +Gdn::sql() + ->select('*') + ->from('Discussion') + ->where('DiscussionID', $discussionID) + ->get()->resultArray(); +``` + +You can also use the `firstRow()` method if you want to retrieve only one result. +``` +Gdn::sql() + ->select('*') + ->from('Discussion') + ->where('DiscussionID', $discussionID) + ->firstRow(); +``` + Note that this is an impractical query to use in your addon, because this functionality already exists in a model: ``` From 911934fd2e8c85b455edfb62277bf9bea3d67076 Mon Sep 17 00:00:00 2001 From: Mathilde Date: Sat, 14 Dec 2019 22:35:42 +0100 Subject: [PATCH 2/2] Update database.md --- content/developer/framework/database.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/developer/framework/database.md b/content/developer/framework/database.md index 4498cdb6..b200c945 100644 --- a/content/developer/framework/database.md +++ b/content/developer/framework/database.md @@ -37,7 +37,8 @@ Gdn::sql() ->select('*') ->from('Discussion') ->where('DiscussionID', $discussionID) - ->get()->resultArray(); + ->get() + ->resultArray(); ``` You can also use the `firstRow()` method if you want to retrieve only one result. @@ -46,6 +47,7 @@ Gdn::sql() ->select('*') ->from('Discussion') ->where('DiscussionID', $discussionID) + ->get() ->firstRow(); ```