blob: e23f1f5759e537d980f1da3c7c83d27809faf746 [file] [log] [blame]
admin3b60ae42006-09-25 23:26:03 +00001<!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
admin17a890d2006-09-27 20:42:42 +000010<script type="text/javascript" src="../nav/nav.js"></script>
admin2296fc32006-09-27 21:07:02 +000011<script type="text/javascript" src="../nav/prototype.lite.js"></script>
admin17a890d2006-09-27 20:42:42 +000012<script type="text/javascript" src="../nav/moo.fx.js"></script>
admin3b60ae42006-09-25 23:26:03 +000013<script type="text/javascript">
14window.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>
admin41a16852006-09-26 18:17:19 +000036<td><h1>Code Igniter User Guide Version 1.5.0</h1></td>
admin3b60ae42006-09-25 23:26:03 +000037<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> &nbsp;&#8250;&nbsp;
49<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
50<a href="index.html">Database Library</a> &nbsp;&#8250;&nbsp;
51Database 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&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<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>&nbsp; This class must be initialized independently since it is a separate class from the main Database class.
70More 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&nbsp;&nbsp;&nbsp; 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&nbsp;&nbsp;&nbsp; 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 />
115foreach($dbs as $db)<br />
116{<br />
117&nbsp;&nbsp;&nbsp; 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 />
128foreach ($tables as $table)<br />
129{<br />
130&nbsp;&nbsp;&nbsp; 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.
138Returns a boolean TRUE/FALSE. Usage example:</p>
139
140<code>
141if ($this->dbutil->table_exists('table_name'))<br />
142{<br />
143&nbsp;&nbsp;&nbsp; // 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>
155if ($this->dbutil->optimize_table('table_name'))<br />
156{<br />
157&nbsp;&nbsp;&nbsp; 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>
169if ($this->dbutil->optimize_table('table_name'))<br />
170{<br />
171&nbsp;&nbsp;&nbsp; echo 'Success!'<br />
172}
173</code>
174
175<p><strong>Note:</strong> Not all database platforms support table repairs.</p>
176
177
178
admine5bb9362006-09-27 00:31:22 +0000179<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 />
186if ($result !== FALSE)<br />
187{<br />
188&nbsp;&nbsp;&nbsp; print_r($result);<br />
189}
190</code>
191
192<p><strong>Note:</strong> Not all database platforms support table optimization.</p>
admin3b60ae42006-09-25 23:26:03 +0000193
194
195
196
197</div>
198<!-- END CONTENT -->
199
200
201<div id="footer">
202<p>
203Previous Topic:&nbsp;&nbsp;<a href="call_function.html">Custom Function Calls</a>
204&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
205<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
206<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
admine5bb9362006-09-27 00:31:22 +0000207Next Topic:&nbsp;&nbsp;<a href="export.html">Database Export Class</a>
admin3b60ae42006-09-25 23:26:03 +0000208<p>
209<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
210</div>
211
212</body>
213</html>