【问题标题】:error after run php index.php console migrate运行 php index.php 控制台迁移后出错
【发布时间】:2018-09-25 23:52:33
【问题描述】:

我想在 CodeIgniter 中进行数据库迁移,但出现此错误

c:\xampp\htdocs\r_project>php index.php console migrate
PHP Notice:  Undefined index: HTTP_HOST in C:\xampp\htdocs\r_project\application
\config\config.php on line 43

Notice: Undefined index: HTTP_HOST in C:\xampp\htdocs\r_project\application\conf
ig\config.php on line 43

A PHP Error was encountered

Severity:    Notice
Message:     Undefined index: HTTP_HOST
Filename:    C:\xampp\htdocs\r_project\application\config\config.php
Line Number: 43

Backtrace:
        File: C:\xampp\htdocs\r_project\application\config\config.php
        Line: 43
        Function: _error_handler

        File: C:\xampp\htdocs\r_project\index.php
        Line: 316
        Function: require_once



ERROR: An Error Was Encountered

        You have not specified a database connection group via $active_group in
your config/database.php file.

我已经用这个设置了我的 config.php

$isSSL = function(){
    if( !empty( $_SERVER['https'] ) )
        return true;

    if( !empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' )
        return true;

    if ( !isset($_SERVER['SERVER_PORT']))
        return false;

    if( $_SERVER['SERVER_PORT'] == 443)
        return true;

    return false;
};

$prot = $isSSL() ? 'https://' : 'http://';
$host = $_SERVER["HTTP_HOST"];
$config['base_url'] = $prot . $host . "/";

除此之外。我必须在文件夹 \application\config\development\database.php 中设置我的 database.php 文件

我应该为此做些什么。真的需要帮助

【问题讨论】:

  • 尝试将 $isSSL = function() 替换为函数 isSSL()。通过 $prot = isSSL() 调用它? 'https://' : 'http://';
  • 我认为错误在database.php中。请重新检查一次。
  • @Gulshan 感谢您的重播。但不工作。显示另一个错误
  • @438sunil 我需要将 database.php 放入 config/development/database.php

标签: mysql database codeigniter migration config


【解决方案1】:

就你得到的错误而言,试试这个:

$host = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']);

在设置数据库配置文件方面,我们需要了解更多才能回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2011-03-13
    • 2018-12-28
    • 1970-01-01
    • 2020-10-24
    • 2018-07-09
    相关资源
    最近更新 更多