admin | fb28bb8 | 2006-09-24 17:59:33 +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 |
|
| 10 | <script type="text/javascript" src="../scripts/nav.js"></script>
|
| 11 | <script type="text/javascript" src="../scripts/prototype.lite.js"></script>
|
| 12 | <script type="text/javascript" src="../scripts/moo.fx.js"></script>
|
| 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>
|
| 36 | <td><h1>Code Igniter User Guide Version 1.4.1</h1></td>
|
| 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 | Configuration
|
| 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 |
|
| 66 | <h1>Database Configuration</h1>
|
| 67 |
|
| 68 | <p>Code Igniter has a config file that lets you store your database connection values (username, password, database name, etc.).
|
| 69 | The 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 |
|
| 85 | <p>The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store
|
| 86 | multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.)
|
| 87 | under a single installation, you can set up a connection group for each, then switch between groups as needed.
|
| 88 | For 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 |
|
| 100 |
|
| 101 | <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"
|
| 106 | for 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>
|
| 111 | <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>
|
| 116 | <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 Code Igniter installations to share one database.</li>
|
| 117 | <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>
|
| 120 | <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.)
|
| 124 | not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and
|
| 125 | the 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>
|
| 135 | Previous Topic: <a href="examples.html">Quck Start: Usage Examples</a>
|
| 136 | ·
|
| 137 | <a href="#top">Top of Page</a> ·
|
| 138 | <a href="../index.html">User Guide Home</a> ·
|
| 139 | Next Topic: <a href="connecting.html">Connecting to your Database</a>
|
| 140 | <p>
|
| 141 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 142 | </div>
|
| 143 |
|
| 144 | </body>
|
| 145 | </html> |