blob: dd883d192f3146337a650a610b4e28eb04e491c9 [file] [log] [blame]
adminfb28bb82006-09-24 17:59:33 +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
Derek Allardd2df9bc2007-04-15 17:41:17 +00005<title>CodeIgniter User Guide</title>
adminfb28bb82006-09-24 17:59:33 +00006
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>
adminfb28bb82006-09-24 17:59:33 +000013<script type="text/javascript">
14window.onload = function() {
admine334c472006-10-21 19:44:22 +000015 myHeight = new fx.Height('nav', {duration: 400});
adminfb28bb82006-09-24 17:59:33 +000016 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' />
Derek Allardd2df9bc2007-04-15 17:41:17 +000025<meta name='description' content='CodeIgniter User Guide' />
adminfb28bb82006-09-24 17:59:33 +000026
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>
Derek Allardd2df9bc2007-04-15 17:41:17 +000036<td><h1>CodeIgniter User Guide Version 1.5.3</h1></td>
adminc0d5d522006-10-30 19:40:35 +000037<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
adminfb28bb82006-09-24 17:59:33 +000038</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">
Derek Allardd2df9bc2007-04-15 17:41:17 +000048<a href="http://www.codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
adminfb28bb82006-09-24 17:59:33 +000049<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
50<a href="index.html">Database Library</a> &nbsp;&#8250;&nbsp;
51Configuration
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
66<h1>Database Configuration</h1>
67
Derek Allardd2df9bc2007-04-15 17:41:17 +000068<p>CodeIgniter has a config file that lets you store your database connection values (username, password, database name, etc.).
adminfb28bb82006-09-24 17:59:33 +000069The config file is located at:
70
71<p><kbd>application/config/database.php</kbd></p>
72
73<p>The config settings are stored in a multi-dimensional array with this prototype:</p>
74
75<code>$db['default']['hostname'] = "localhost";<br />
76$db['default']['username'] = "root";<br />
77$db['default']['password'] = "";<br />
78$db['default']['database'] = "database_name";<br />
79$db['default']['dbdriver'] = "mysql";<br />
80$db['default']['dbprefix'] = "";<br />
81$db['default']['pconnect'] = TRUE;<br />
82$db['default']['db_debug'] = FALSE;<br />
83$db['default']['active_r'] = TRUE;</code>
84
admine334c472006-10-21 19:44:22 +000085<p>The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store
86multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.)
adminfb28bb82006-09-24 17:59:33 +000087under a single installation, you can set up a connection group for each, then switch between groups as needed.
88For example, to set up a "test" environment you would do this:</p>
89
90<code>$db['test']['hostname'] = "localhost";<br />
91$db['test']['username'] = "root";<br />
92$db['test']['password'] = "";<br />
93$db['test']['database'] = "database_name";<br />
94$db['test']['dbdriver'] = "mysql";<br />
95$db['test']['dbprefix'] = "";<br />
96$db['test']['pconnect'] = TRUE;<br />
97$db['test']['db_debug'] = FALSE;<br />
98$db['test']['active_r'] = TRUE;</code>
99
admine334c472006-10-21 19:44:22 +0000100
adminfb28bb82006-09-24 17:59:33 +0000101<p>Then, to globally tell the system to use that group you would set this variable located in the config file:</p>
102
103<code>$active_group = "test";</code>
104
105<p>Note: The name "test" is arbitrary. It can be anything you want. By default we've used the word "default"
106for the primary connection, but it too can be renamed to something more relevant to your project.</p>
107
108<h3>Explanation of Values:</h3>
109
110<ul>
admine334c472006-10-21 19:44:22 +0000111<li><strong>hostname</strong> - The hostname of your database server. Often this is "localhost".</li>
112<li><strong>username</strong> - The username used to connect to the database.</li>
113<li><strong>password</strong> - The password used to connect to the database.</li>
114<li><strong>database</strong> - The name of the database you want to connect to.</li>
115<li><strong>dbdriver</strong> - The database type. ie: mysql, postgre, obdc, etc. Must be specified in lower case.</li>
Derek Allardd2df9bc2007-04-15 17:41:17 +0000116<li><strong>dbprefix</strong> - An optional table prefix which will added to the table name when running <a href="active_record.html">Active Record</a> queries. This permits multiple CodeIgniter installations to share one database.</li>
admine334c472006-10-21 19:44:22 +0000117<li><strong>pconnect</strong> - TRUE/FALSE (boolean) - Whether to use a persistent connection.</li>
118<li><strong>db_debug</strong> - TRUE/FALSE (boolean) - Whether database errors should be displayed.</li>
119<li><strong>active_r</strong> - TRUE/FALSE (boolean) - Whether to load the <a href="active_record.html">Active Record Class</a>. If you are not using the active record class you can have it omitted when the database classes are initialized in order to utilize less resources.</li>
adminfb28bb82006-09-24 17:59:33 +0000120<li><strong>port</strong> - The database port number. Currently only used with the Postgre driver.</li>
121</ul>
122
123<p class="important"><strong>Note:</strong> Depending on what database platform you are using (MySQL, Postgre, etc.)
124not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and
125the database name will be the path to your database file. The information above assumes you are using MySQL.</p>
126
127
128
129</div>
130<!-- END CONTENT -->
131
132
133<div id="footer">
134<p>
135Previous Topic:&nbsp;&nbsp;<a href="examples.html">Quck Start: Usage Examples</a>
136&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
137<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
138<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
139Next Topic:&nbsp;&nbsp;<a href="connecting.html">Connecting to your Database</a>
140<p>
Derek Allardd2df9bc2007-04-15 17:41:17 +0000141<p><a href="http://www.codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2007 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
adminfb28bb82006-09-24 17:59:33 +0000142</div>
143
144</body>
145</html>