admin | 3b60ae4 | 2006-09-25 23:26:03 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
admin | 3b60ae4 | 2006-09-25 23:26:03 +0000 | [diff] [blame] | 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
admin | 41a1685 | 2006-09-26 18:17:19 +0000 | [diff] [blame] | 36 | <td><h1>Code Igniter User Guide Version 1.5.0</h1></td>
|
admin | 3b60ae4 | 2006-09-25 23:26:03 +0000 | [diff] [blame] | 37 | <td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | <a href="index.html">Database Library</a> ›
|
| 51 | Database Utilities Class
|
| 52 | </td>
|
| 53 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
| 54 | </tr>
|
| 55 | </table>
|
| 56 | <!-- END BREADCRUMB -->
|
| 57 |
|
| 58 |
|
| 59 | <br clear="all" />
|
| 60 |
|
| 61 |
|
| 62 | <!-- START CONTENT -->
|
| 63 | <div id="content">
|
| 64 |
|
| 65 | <h1>Database Utilities Class</h1>
|
| 66 |
|
| 67 | <p>The Database Utilities Class contains functions that help you manage your database.</p>
|
| 68 |
|
| 69 | <p class="important"><strong>Important:</strong> This class must be initialized independently since it is a separate class from the main Database class.
|
| 70 | More info below...</p>
|
| 71 |
|
| 72 |
|
| 73 | <h2>Initializing the Utilities Class</h2>
|
| 74 |
|
| 75 | <p>To initialize this class please use the following code:</p>
|
| 76 |
|
| 77 | <code>$this->load->dbutil()</code>
|
| 78 |
|
| 79 | <p>You can also autoload this class from within your <dfn>config/autoload.php</dfn> file by specifying <kbd>dbutil</kbd> in the <samp>$autoload['libraries']</samp> array.</p>
|
| 80 |
|
| 81 | <p>Once initialized you will access the functions using the <dfn>$this->dbutil</dfn> object:</p>
|
| 82 |
|
| 83 | <code>$this->dbutil->some_function()</code>
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 | <h2>$this->dbutil->create_database('db_name')</h2>
|
| 88 |
|
| 89 | <p>Permits you to create a database using the name specified in the first parameter. Returns TRUE/FALSE based on success or failure:</p>
|
| 90 |
|
| 91 | <code>if ($this->dbutil->create_database('my_db'))<br />
|
| 92 | {<br />
|
| 93 | echo 'Database created!';<br />
|
| 94 | }</code>
|
| 95 |
|
| 96 |
|
| 97 | <h2>$this->dbutil->drop_database('table_name')</h2>
|
| 98 |
|
| 99 | <p>Permits you to drop a database using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:</p>
|
| 100 |
|
| 101 | <code>if ($this->dbutil->drop_database('my_db'))<br />
|
| 102 | {<br />
|
| 103 | echo 'Database deleted!';<br />
|
| 104 | }</code>
|
| 105 |
|
| 106 |
|
| 107 | <h2>$this->dbutil->list_databases()</h2>
|
| 108 |
|
| 109 | <p>Returns an array of database names:</p>
|
| 110 |
|
| 111 |
|
| 112 | <code>
|
| 113 | $dbs = $this->dbutil->list_databases();<br />
|
| 114 | <br />
|
| 115 | foreach($dbs as $db)<br />
|
| 116 | {<br />
|
| 117 | echo $db;<br />
|
| 118 | }</code>
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 | <h2>$this->dbutil->list_tables();</h2>
|
| 123 |
|
| 124 | <p>Returns an array containing the names of all the tables in the database you are currently connected to. Example:</p>
|
| 125 |
|
| 126 | <code>$tables = $this->dbutil->list_tables()<br />
|
| 127 | <br />
|
| 128 | foreach ($tables as $table)<br />
|
| 129 | {<br />
|
| 130 | echo $table;<br />
|
| 131 | }
|
| 132 | </code>
|
| 133 |
|
| 134 |
|
| 135 | <h2>$this->dbutil->table_exists();</h2>
|
| 136 |
|
| 137 | <p>Sometimes it's helpful to know whether a particular table exists before running an operation on it.
|
| 138 | Returns a boolean TRUE/FALSE. Usage example:</p>
|
| 139 |
|
| 140 | <code>
|
| 141 | if ($this->dbutil->table_exists('table_name'))<br />
|
| 142 | {<br />
|
| 143 | // some code...<br />
|
| 144 | }
|
| 145 | </code>
|
| 146 |
|
| 147 | <p>Note: Replace <em>table_name</em> with the name of the table you are looking for.</p>
|
| 148 |
|
| 149 |
|
| 150 | <h2>$this->dbutil->optimize_table('table_name');</h2>
|
| 151 |
|
| 152 | <p>Permits you to optimize a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:</p>
|
| 153 |
|
| 154 | <code>
|
| 155 | if ($this->dbutil->optimize_table('table_name'))<br />
|
| 156 | {<br />
|
| 157 | echo 'Success!'<br />
|
| 158 | }
|
| 159 | </code>
|
| 160 |
|
| 161 | <p><strong>Note:</strong> Not all database platforms support table optimization.</p>
|
| 162 |
|
| 163 |
|
| 164 | <h2>$this->dbutil->repair_table('table_name');</h2>
|
| 165 |
|
| 166 | <p>Permits you to repair a table using the table name specified in the first parameter. Returns TRUE/FALSE based on success or failure:</p>
|
| 167 |
|
| 168 | <code>
|
| 169 | if ($this->dbutil->optimize_table('table_name'))<br />
|
| 170 | {<br />
|
| 171 | echo 'Success!'<br />
|
| 172 | }
|
| 173 | </code>
|
| 174 |
|
| 175 | <p><strong>Note:</strong> Not all database platforms support table repairs.</p>
|
| 176 |
|
| 177 |
|
| 178 |
|
admin | e5bb936 | 2006-09-27 00:31:22 +0000 | [diff] [blame] | 179 | <h2>$this->dbutil->optimize_database();</h2>
|
| 180 |
|
| 181 | <p>Permits you to optimize the database your DB class is currently connected to. Returns an array containing the returned status messages or FALSE on failure.</p>
|
| 182 |
|
| 183 | <code>
|
| 184 | $result = $this->dbutil->optimize_databas();<br />
|
| 185 | <br />
|
| 186 | if ($result !== FALSE)<br />
|
| 187 | {<br />
|
| 188 | print_r($result);<br />
|
| 189 | }
|
| 190 | </code>
|
| 191 |
|
| 192 | <p><strong>Note:</strong> Not all database platforms support table optimization.</p>
|
admin | 3b60ae4 | 2006-09-25 23:26:03 +0000 | [diff] [blame] | 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 | </div>
|
| 198 | <!-- END CONTENT -->
|
| 199 |
|
| 200 |
|
| 201 | <div id="footer">
|
| 202 | <p>
|
| 203 | Previous Topic: <a href="call_function.html">Custom Function Calls</a>
|
| 204 | ·
|
| 205 | <a href="#top">Top of Page</a> ·
|
| 206 | <a href="../index.html">User Guide Home</a> ·
|
admin | e5bb936 | 2006-09-27 00:31:22 +0000 | [diff] [blame] | 207 | Next Topic: <a href="export.html">Database Export Class</a>
|
admin | 3b60ae4 | 2006-09-25 23:26:03 +0000 | [diff] [blame] | 208 | <p>
|
| 209 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 210 | </div>
|
| 211 |
|
| 212 | </body>
|
| 213 | </html> |