官术网_书友最值得收藏!

Configuration settings

As for the other configuration settings you have done for CodeIgniter, the file you need to modify is in /www/codeigniter/application/config. This time, the file you need to update is database.php. This file contains all the information necessary for CodeIgniter to connect to your database. Open the file, you will see the options that you must set along with a few other options that you can leave at the default, for now.

$active_group = "default"; $active_record = TRUE; $db['default']['hostname'] = "localhost"; $db['default']['username'] = ""; $db['default']['password'] = ""; $db['default']['database'] = ""; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci";

The options you must fill in are:

  • hostname: The location of your database, for example, localhost or an IP address.
  • username and password: The username and password of a database user with sufficient permissions to do whatever you may want your site to do. This is not (usually) the same username and password as of your site or your ISP's control panel.
  • database: The name of your database, for example, websites.
  • dbdriver: The type of database you're using. At the time of writing, the options CI offers are MySQL, MySQLi, Postgre SQL, ODBC, and MS SQL.

From experience, it can be said that one of the most difficult things to set up on a new CI site can be a link to the database. You may need to consult your ISP if in doubt—sometimes their database runs at a different address than their web server's. If you are using MySQL, they may offer phpMyAdmin, which usually tells you the hostname—this may be localhost or it may be an IP address.

Note

If you are new to phpMyAdmin you can find all you need in this Packt book:

http://www.packtpub.com/ mastering-phpmyadmin-3-1-fourth-edition/book

It is strongly recommended!

You'll note that this part of the config file is actually a multi-dimensional array. Within $db is an array called default, and you're adding key/variable pairs like hostname = 127.0.0.1 to that array. Because of this you can set up other databases, as secondary arrays. You can swap between them easily by simply changing the $active_group setting to the name of another array.

This makes it possible to run a site with several database options—for instance, a test database and a production database—and to swap between them easily. Or you might need to draw information from two separate databases.

主站蜘蛛池模板: 阿拉善右旗| 涞源县| 财经| 鄢陵县| 水城县| 水富县| 阳城县| 灌南县| 汝城县| 永春县| 佛教| 道真| 读书| 绥阳县| 常德市| 安阳县| 惠安县| 和田市| 射洪县| 广东省| 明光市| 巍山| 永修县| 文安县| 临夏县| 柳河县| 凤冈县| 逊克县| 黄大仙区| 汉寿县| 巩留县| 垫江县| 遵化市| 柘荣县| 精河县| 光泽县| 阿勒泰市| 胶州市| 屏山县| 新疆| 民权县|