File tree Expand file tree Collapse file tree
user_guide_src/source/database Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -102,6 +102,35 @@ function config(string $name, bool $getShared = true)
102102
103103//--------------------------------------------------------------------
104104
105+ if (! function_exists ('db_connnect ' ))
106+ {
107+ /**
108+ * Grabs a database connection and returns it to the user.
109+ *
110+ * This is a convenience wrapper for \Config\Database::connect()
111+ * and supports the same parameters. Namely:
112+ *
113+ * When passing in $db, you may pass any of the following to connect:
114+ * - group name
115+ * - existing connection instance
116+ * - array of database configuration values
117+ *
118+ * If $getShared === false then a new connection instance will be provided,
119+ * otherwise it will all calls will return the same instance.
120+ *
121+ * @param \CodeIgniter\Database\ConnectionInterface|array|string $db
122+ * @param bool $getShared
123+ *
124+ * @return \CodeIgniter\Database\BaseConnection
125+ */
126+ function db_connect ($ db , bool $ getShared = true )
127+ {
128+ return \Config \Database::connect ($ db , $ getShared );
129+ }
130+ }
131+
132+ //--------------------------------------------------------------------
133+
105134if (! function_exists ('view ' ))
106135{
107136 /**
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ If the above function does **not** contain any information in the first
1414parameter it will connect to the default group specified in your database config
1515file. For most people, this is the preferred method of use.
1616
17+ A convenience method exists that is purely a wrapper around the above line
18+ and is provided for your convenience::
19+
20+ $db = db_connect();
21+
1722Available Parameters
1823--------------------
1924
@@ -89,7 +94,7 @@ the same format as the groups are defined in the configuration file::
8994 'failover' => [],
9095 'port' => 3306,
9196 ];
92- $db = \Config\Database::connect($custom);
97+ $db = \Config\Database::connect($custom);
9398
9499
95100Reconnecting / Keeping the Connection Alive
You can’t perform that action at this time.
0 commit comments