Skip to content

Commit

Permalink
Merge pull request #7379 from kenjis/docs-improve-database-results.rst
Browse files Browse the repository at this point in the history
docs: improve getResult() in database/results.rst
  • Loading branch information
kenjis authored Mar 25, 2023
2 parents 829bcb2 + e40d25f commit 6624395
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion user_guide_src/source/database/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################
Working With Databases
Working with Databases
######################

CodeIgniter comes with a full-featured and very fast abstracted database
Expand Down
23 changes: 17 additions & 6 deletions user_guide_src/source/database/results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ There are several ways to generate query results:

.. contents::
:local:
:depth: 2
:depth: 3

*************
Result Arrays
Expand All @@ -16,26 +16,37 @@ getResult()
===========

This method returns the query result as an array of **objects**, or
**an empty array** on failure. Typically you'll use this in a foreach
**an empty array** on failure.

Getting an Array of stdClass
----------------------------

Typically you'll use this in a foreach
loop, like this:

.. literalinclude:: results/001.php

The above method is an alias of ``getResultObject()``.
The above method is an alias of :php:meth:`CodeIgniter\\Database\\BaseResult::getResultObject()`.

Getting an Array of Array
-------------------------

You can pass in the string 'array' if you wish to get your results
as an array of arrays:

.. literalinclude:: results/002.php

The above usage is an alias of ``getResultArray()``.
The above usage is an alias of `getResultArray()`_.

Getting an Array of Custom Object
---------------------------------

You can also pass a string to ``getResult()`` which represents a class to
instantiate for each result object

.. literalinclude:: results/003.php

The above method is an alias of ``getCustomResultObject()``.
The above method is an alias of `getCustomResultObject()`_.

getResultArray()
================
Expand Down Expand Up @@ -272,7 +283,7 @@ Class Reference
Returns the query results as an array of rows, where each
row is an object of type ``stdClass``.

Usage: see `Result Arrays`_.
Usage: see `Getting an Array of stdClass`_.

.. php:method:: getCustomResultObject($class_name)
Expand Down

0 comments on commit 6624395

Please sign in to comment.