作者:无情的有情人家_834 | 来源:互联网 | 2014-06-12 18:37
项目根目录上建立config.php:<?phpif(!defined('THINK_PATH'))exit();returnarray('DB_TYPE'>'mysql',//数据库类...
项目根目录上建立config.php:
- if(!defined(&#39;THINK_PATH&#39;)) exit();
- return array(
- &#39;DB_TYPE&#39; => &#39;mysql&#39;,
- &#39;DB_HOST&#39; => &#39;localhost&#39;,
- &#39;DB_NAME&#39; => &#39;aoli&#39;,
- &#39;DB_USER&#39; => &#39;root&#39;,
- &#39;DB_PWD&#39; => &#39;&#39;,
- &#39;DB_PREFIX&#39; => &#39;&#39;,
- &#39;DB_CHARSET&#39; => &#39;utf8&#39;,
- &#39;DB_PORT&#39; => &#39;3306&#39;,
- );
- ?>
\Home\Conf\config.php
- $arr1=array{
- &#39;URL_MODEL&#39;=>2,
- };
- $arr2=include &#39;./config.php&#39;;
- return array_merge($arr1,$arr2);
- ?>
\Admin\Conf\config.php
- $arr1=array{
- &#39;URL_MODEL&#39;=>1,
- };
- $arr2=include &#39;./config.php&#39;;
- return array_merge($arr1,$arr2);
- ?>
主从数据库设置
比较适合高并发,高负载,可以到\ThinkPHP\Common\convention.php中查看默认的系统常量设置.
config.php
- return array(
-
-
- &#39;URL_MODE&#39;=>0,
- &#39;DB_TYPE&#39;=>&#39;mysql&#39;,
- &#39;DB_HOST&#39;=>&#39;localhost,192.168.1.2&#39;,
- &#39;DB_PORT&#39;=>&#39;3306&#39;,
- &#39;DB_NAME&#39;=>&#39;thinkphptest&#39;,
- &#39;DB_USER&#39;=>&#39;root&#39;,
- &#39;DB_PWD&#39;=>&#39;password&#39;,
-
- &#39;DB_PREFIX&#39;=>&#39;think_&#39;,
-
- &#39;DB_DEPLOY_TYPE&#39;=>1,
- &#39;DB_RW_SEPARATE&#39;=>ture,
- );
- ?>
在某个action中读取数据库文件参数:
- $hh=C(&#39;DB_HOST&#39;);
- $pp=C(&#39;DB_PREFIX&#39;);
- $this->assain(&#39;h&#39;,$hh);
- $this->assain(&#39;p&#39;,$pp);
- $this->display();
这个action下的tpl:
数据库服务器地址:{$h}
数据库表前缀:{$p}