zoukankan      html  css  js  c++  java
  • thikphp创建共享数据config.php

    要求:前台,后台;只需要配置一个config.php 其他文件共享

    默认配置是 

    Index/Conf/config.php

    Admin/Conf/config.php

    代码:

    return array(
        DB_HOST'               => '127.0.0.1', // 服务器地址
        DB_NAME'               => 'phpcms',          // 数据库名
        DB_USER'               => 'root',      // 用户名
        DB_PWD'                => 'root',          // 密码
        DB_PREFIX'             => 'v9_',    // 数据库表前缀
    )

    要配置两次连接,如果有user的话还需要配置三次。

    创立共享配置

    1.根目录下创建Conf/config.php

    代码: 

    <?php
    return array(
        'DB_HOST'               => '127.0.0.1', // 服务器地址
        'DB_NAME'               => 'phpcms',          // 数据库名
        'DB_USER'               => 'root',      // 用户名
        'DB_PWD'                => 'root',          // 密码
        'DB_PREFIX'             => 'v9_',    // 数据库表前缀
    );
    ?>

    2.在Index/Conf/config.php 或者是Admin/Conf/config.php,引入文件

    $config = array(
        
    );
    return array_merge(include('./Conf/config.php'),$config);

    3.在IndexAction.php 输出

    <?php
    // 本类由系统自动生成,仅供测试用途
    class IndexAction extends Action {
        public function index(){
            $db = M('admin');
            $result = $db->select();
        
            print_r($result);
            //echo C('db_host');
            //W$this->display();
        }
    
    }
  • 相关阅读:

    bzoj3052: [wc2013]糖果公园
    莫队算法心得
    bzoj1104: [POI2007]洪水pow
    bzoj1102: [POI2007]山峰和山谷Grz
    bzoj1121: [POI2008]激光发射器SZK
    bzoj1113: [Poi2008]海报PLA
    bzoj1103: [POI2007]大都市meg
    bzoj1396: 识别子串
    bzoj3756: Pty的字符串
  • 原文地址:https://www.cnblogs.com/wesky/p/4947036.html
Copyright © 2011-2022 走看看