Skip to content

Commit 23829e3

Browse files
authored
Merge pull request #7554 from kenjis/fix-docs-database-connecting.rst
docs: improve database/connecting.rst
2 parents dda5a01 + b93a901 commit 23829e3

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

user_guide_src/source/database/connecting.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ Connecting to your Database
66
:local:
77
:depth: 2
88

9+
Connecting to a Database
10+
========================
11+
12+
Connecting to the Default Group
13+
-------------------------------
14+
915
You can connect to your database by adding this line of code in any
1016
function where it is needed, or in your class constructor to make the
1117
database available globally in that class.
1218

1319
.. literalinclude:: connecting/001.php
20+
:lines: 2-
1421

1522
If the above function does **not** contain any information in the first
1623
parameter, it will connect to the default group specified in your database config
@@ -20,27 +27,29 @@ A convenience method exists that is purely a wrapper around the above line
2027
and is provided for your convenience:
2128

2229
.. literalinclude:: connecting/002.php
30+
:lines: 2-
2331

2432
Available Parameters
2533
--------------------
2634

2735
**\\Config\\Database::connect($group = null, bool $getShared = true): BaseConnection**
2836

29-
#. ``$group``: The database group name, a string that must match the config class' property name. Default value is ``$config->defaultGroup``.
37+
#. ``$group``: The database group name, a string that must match the config class' property name. Default value is ``Config\Database::$defaultGroup``.
3038
#. ``$getShared``: true/false (boolean). Whether to return the shared connection (see
3139
Connecting to Multiple Databases below).
3240

33-
Manually Connecting to a Database
34-
---------------------------------
41+
Connecting to Specific Group
42+
----------------------------
3543

3644
The first parameter of this function can **optionally** be used to
3745
specify a particular database group from your config file. Examples:
3846

3947
To choose a specific group from your config file you can do this:
4048

4149
.. literalinclude:: connecting/003.php
50+
:lines: 2-
4251

43-
Where group_name is the name of the connection group from your config
52+
Where ``group_name`` is the name of the connection group from your config
4453
file.
4554

4655
Multiple Connections to Same Database
@@ -51,6 +60,7 @@ database connection every time. If you need to have a separate connection
5160
to the same database, send ``false`` as the second parameter:
5261

5362
.. literalinclude:: connecting/004.php
63+
:lines: 2-
5464

5565
Connecting to Multiple Databases
5666
================================
@@ -59,6 +69,7 @@ If you need to connect to more than one database simultaneously you can
5969
do so as follows:
6070

6171
.. literalinclude:: connecting/005.php
72+
:lines: 2-
6273

6374
Note: Change the words ``group_one`` and ``group_two`` to the specific
6475
group names you are connecting to.
@@ -76,6 +87,7 @@ a connection that uses your custom settings. The array passed in must be
7687
the same format as the groups are defined in the configuration file:
7788

7889
.. literalinclude:: connecting/006.php
90+
:lines: 2-
7991

8092
Reconnecting / Keeping the Connection Alive
8193
===========================================
@@ -90,11 +102,13 @@ or re-establish it.
90102
does not ping the server but it closes the connection then connects again.
91103

92104
.. literalinclude:: connecting/007.php
105+
:lines: 2-
93106

94-
Manually closing the Connection
107+
Manually Closing the Connection
95108
===============================
96109

97110
While CodeIgniter intelligently takes care of closing your database
98111
connections, you can explicitly close the connection.
99112

100113
.. literalinclude:: connecting/008.php
114+
:lines: 2-

0 commit comments

Comments
 (0)