diff options
author | Derek Allard <derek.allard@ellislab.com> | 2010-02-04 17:47:01 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2010-02-04 17:47:01 +0100 |
commit | e7f0325af984392aa4c509dc5a5ca409f5e9474a (patch) | |
tree | 1fbd61e82de91af494242b33fb812f870da86c4a | |
parent | 5192e5c8e94f956784063812da6378adb3cb1b7c (diff) |
database exists function in dbutil
-rw-r--r-- | system/database/DB_utility.php | 14 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 | ||||
-rw-r--r-- | user_guide/database/utilities.html | 19 |
3 files changed, 34 insertions, 0 deletions
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 94e7a0bda..af62dcf3d 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -75,6 +75,20 @@ class CI_DB_utility extends CI_DB_forge { // -------------------------------------------------------------------- /** + * Determine if a particular database exists + * + * @access public + * @param string + * @return boolean + */ + function database_exists($database_name) + { + return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** * Optimize Table * * @access public diff --git a/user_guide/changelog.html b/user_guide/changelog.html index fc35cdf7f..88d8a1621 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -74,6 +74,7 @@ SVN Revision: </p> </li> <li>Database <ul> + <li>Added <kbd>database_exists()</kbd> to the <a href="database/utilities.html">Database Utilities Class</a>.</li> <li>Semantic change to db->version() function to allow a list of exceptions for databases with functions to return version string instead of specially formed SQL queries. Currently this list only includes Oracle and SQLite.</li> <li>Fixed a bug where driver specific table identifier protection could lead to malformed queries in the <kbd>field_data()</kbd> functions.</li> <li>Fixed a bug where an undefined class variable was referenced in database drivers.</li> diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html index a26e0f35b..f46db6820 100644 --- a/user_guide/database/utilities.html +++ b/user_guide/database/utilities.html @@ -66,6 +66,7 @@ Database Utility Class <ul> <li><a href="#init">Initializing the Utility Class</a></li> <li><a href="#list">Listing your Databases</a></li> +<li><a href="#exists">Checking for a specific Database</a></li> <li><a href="#opttb">Optimizing your Tables</a></li> <li><a href="#repair">Repairing your Databases</a></li> <li><a href="#optdb">Optimizing your Database</a></li> @@ -99,6 +100,24 @@ foreach($dbs as $db)<br /> {<br /> echo $db;<br /> }</code> + + +<h2><a name="exists"></a>$this->db->database_exists();</h2> + +<p>Sometimes it's helpful to know whether a particular database exists. +Returns a boolean TRUE/FALSE. Usage example:</p> + +<code> +if ($this->db->database_exists('database_name'))<br /> +{<br /> + // some code...<br /> +} +</code> + +<p>Note: Replace <em>database_name</em> with the name of the table you are looking for.</p> + + + <h2><a name="opttb"></a>$this->dbutil->optimize_table('table_name');</h2> <p class="important"><strong>Note:</strong> This features is only available for MySQL/MySQLi databases.</p> |