@@ -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+
915You can connect to your database by adding this line of code in any
1016function where it is needed, or in your class constructor to make the
1117database available globally in that class.
1218
1319.. literalinclude :: connecting/001.php
20+ :lines: 2-
1421
1522If the above function does **not ** contain any information in the first
1623parameter, 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
2027and is provided for your convenience:
2128
2229.. literalinclude :: connecting/002.php
30+ :lines: 2-
2331
2432Available 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
3644The first parameter of this function can **optionally ** be used to
3745specify a particular database group from your config file. Examples:
3846
3947To 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
4453file.
4554
4655Multiple Connections to Same Database
@@ -51,6 +60,7 @@ database connection every time. If you need to have a separate connection
5160to the same database, send ``false `` as the second parameter:
5261
5362.. literalinclude :: connecting/004.php
63+ :lines: 2-
5464
5565Connecting to Multiple Databases
5666================================
@@ -59,6 +69,7 @@ If you need to connect to more than one database simultaneously you can
5969do so as follows:
6070
6171.. literalinclude :: connecting/005.php
72+ :lines: 2-
6273
6374Note: Change the words ``group_one `` and ``group_two `` to the specific
6475group names you are connecting to.
@@ -76,6 +87,7 @@ a connection that uses your custom settings. The array passed in must be
7687the same format as the groups are defined in the configuration file:
7788
7889.. literalinclude :: connecting/006.php
90+ :lines: 2-
7991
8092Reconnecting / 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
97110While CodeIgniter intelligently takes care of closing your database
98111connections, you can explicitly close the connection.
99112
100113.. literalinclude :: connecting/008.php
114+ :lines: 2-
0 commit comments