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

时间:2015-06-23 08:46:46

标签: php mysql database .htaccess codeigniter

实际上我正在尝试将我的codeigniter实时文件配置为localhost。

我有,

  1. 创建了一个名为test_bs
  2. 的数据库
  3. 然后导入表格
  4. 然后更改base_url,如$config['base_url']=http://localhost/gu_ci/';和$config['index_page']='index.php';在config.php
  5. 然后对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;
    
  6. 我的.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]
    

    我收到以下错误:

         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
    

    我已提及Refer1Refer2Refer3Refer4Refer5等等...最后一个链接只显示欢迎消息: enter image description here 但是解决方案都没有帮助我!!

    指导我解决这个问题!!

1 个答案:

答案 0 :(得分:4)

$db['default']['password'] = '';空格,将其删除

使用以下设置

$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;

修改01

使用此.htaccess

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

编辑02

你的文件夹结构应该是

  1. 应用
  2. 资产
    • CSS
      1. boostrap.css
      2. 的style.css
    • JS​​
    • 图像
  3. 系统
  4. .htacess
  5. 的index.php
  6. 所以代码将是:

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