php 无法使用 Codeigniter 中提供的设置连接到您的数据库服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30997994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:11:33  来源:igfitidea点击:

Unable to connect to your database server using the provided settings in Codeigniter

phpmysqldatabase.htaccesscodeigniter

提问by PHP Learner

Actually I'm trying to configure my codeigniter live file to localhost.

实际上,我正在尝试将我的 codeigniter 实时文件配置为本地主机。

I have,

我有,

  1. created a database called test_bs
  2. then imported the tables
  3. Then change the base_urllike $config['base_url']=http://localhost/gu_ci/'; and $config['index_page']='index.php';in config.php
  4. And then did a change on database.php,Which contains

    $active_group = 'default';
    $active_record = TRUE;
    
    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'root';
    $db['default']['password'] = ' ';
    $db['default']['database'] = 'test_bs';
    $db['default']['dbdriver'] = 'mysql';
    $db['default']['dbprefix'] = '';
    $db['default']['pconnect'] = TRUE;
    $db['default']['db_debug'] = TRUE;
    $db['default']['cache_on'] = TRUE;
    $db['default']['cachedir'] = 'application/cache/';
    $db['default']['char_set'] = 'utf8';
    $db['default']['dbcollat'] = 'utf8_general_ci';
    $db['default']['swap_pre'] = '';
    $db['default']['autoinit'] = TRUE;
    $db['default']['stricton'] = FALSE;
    
  1. 创建了一个名为 test_bs 的数据库
  2. 然后导入表
  3. 然后改成base_url这样$config['base_url']=http://localhost/gu_ci/';并$config['index_page']='index.php';在 config.php
  4. 然后对database.php进行了更改,其中包含

    $active_group = 'default';
    $active_record = TRUE;
    
    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'root';
    $db['default']['password'] = ' ';
    $db['default']['database'] = 'test_bs';
    $db['default']['dbdriver'] = 'mysql';
    $db['default']['dbprefix'] = '';
    $db['default']['pconnect'] = TRUE;
    $db['default']['db_debug'] = TRUE;
    $db['default']['cache_on'] = TRUE;
    $db['default']['cachedir'] = 'application/cache/';
    $db['default']['char_set'] = 'utf8';
    $db['default']['dbcollat'] = 'utf8_general_ci';
    $db['default']['swap_pre'] = '';
    $db['default']['autoinit'] = TRUE;
    $db['default']['stricton'] = FALSE;
    

My .htacess file having:

我的 .htacess 文件具有:

  RewriteEngine On
  RewriteBase /new_admin/

  RewriteCond %{REQUEST_URI} PIE.htc
  AddType text/x-component .htc
  RewriteRule (.*) static/PIE.htc [L]

  RewriteCond %{REQUEST_URI} !^/new_admin/static/

  RewriteRule (.*)$ index.php [L]

I'm getting the following error:

我收到以下错误:

     A Database Error Occurred

     Unable to connect to your database server using the provided settings.

     Filename: C:\xampp\htdocs\gunify_ci\system\database\DB_driver.php

     Line Number: 124

I have referred Refer1, Refer2,Refer3,Refer4,Refer5and so on... The last link just display the welcome message like: enter image description hereBut none of the solution helped me!!

我已经提到了Refer1Refer2Refer3Refer4Refer5等等......最后一个链接只显示了如下欢迎信息: 在此处输入图片说明但没有一个解决方案对我有帮助!!

Guide me to solve this!!

指导我解决这个问题!!

回答by Abdulla Nilam

$db['default']['password'] = '';there is an space, remove it

$db['default']['password'] = '';有一个空格,删除它

use below settings

使用以下设置

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'test_bs';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

Edit 01

编辑 01

Use this .htaccess

使用这个 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L] 
</IfModule>

Edit 02

编辑 02

your folder structurer should be

你的文件夹结构应该是

  1. Application
  2. assets
    • css
      1. boostrap.css
      2. style.css
    • js
    • images
  3. system
  4. .htacess
  5. index.php
  1. 应用
  2. 资产
    • css
      1. boostrap.css
      2. 样式文件
    • js
    • 图片
  3. 系统
  4. .htacess
  5. 索引.php

so code will be:

所以代码将是:

<link href="<?php echo base_url(); ?>assets/css/bootstrap.css" rel="stylesheet" />