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();
        }
    
    }
  • 相关阅读:
    json for modern c++(nlohmann json)使用小计
    你到底是如何上网的[转载]
    opencv编译
    二维码解析(编译zxing-cpp)
    otl odbc小计
    解决github clone慢的问题
    网络编程小计
    模板小计
    c++开发遇到的错误和引用配置
    IOCP Input/Output Completion Port IO完成端口
  • 原文地址:https://www.cnblogs.com/wesky/p/4947036.html
Copyright © 2011-2022 走看看