用户
 找回密码
 入住 CI 中国社区
搜索
查看: 8803|回复: 11
收起左侧

数据库的问题,

[复制链接]
发表于 2008-4-13 22:34:53 | 显示全部楼层 |阅读模式
Fatal error: Cannot redeclare class ci_exceptions in D:\web\ci\system\libraries\Exceptions.php on line 27


我在代码里加了行$this->load->database();,就出现上面的提示了。。。不知道怎么回事?
发表于 2008-4-13 23:03:24 | 显示全部楼层
报告你的 CI 版本号,还有是不是自动装载了 databases 类?
发表于 2008-4-13 23:04:07 | 显示全部楼层
应该是在 system/configs/autoload.php 里自动装载了 database
 楼主| 发表于 2008-4-13 23:04:23 | 显示全部楼层
6.1,没有装载的,只是设置了database.php配置文件里对应的数据库信息。
 楼主| 发表于 2008-4-13 23:05:07 | 显示全部楼层
system/configs/autoload.php文件的内容,我没有更改过。

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| AUTO-LOADER
| -------------------------------------------------------------------
| This file specifies which systems should be loaded by default.
|
| In order to keep the framework as light-weight as possible only the
| absolute minimal resources are loaded by default. For example,
| the database is not connected to automatically since no assumption
| is made regarding whether you intend to use it.  This file lets
| you globally define which systems you would like loaded with every
| request.
|
| -------------------------------------------------------------------
| Instructions
| -------------------------------------------------------------------
|
| These are the things you can load automatically:
|
| 1. Libraries
| 2. Helper files
| 3. Plugins
| 4. Custom config files
| 5. Language files
| 6. Models
|
*/

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your system/application/libraries folder.
|
| Prototype:
|
|        $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|        $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|
|        $autoload['plugin'] = array('captcha', 'js_calendar');
*/

$autoload['plugin'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
|        $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files.  Otherwise, leave it blank.
|
*/

$autoload['config'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
|        $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file.  For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/

$autoload['language'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
|        $autoload['model'] = array('model1', 'model2');
|
*/

$autoload['model'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Core Libraries
| -------------------------------------------------------------------
|
| DEPRECATED:  Use $autoload['libraries'] above instead.
|
*/
// $autoload['core'] = array();


?>
发表于 2008-4-13 23:06:13 | 显示全部楼层
呵呵,有可能是 CI bug,需要测试一下。
 楼主| 发表于 2008-4-13 23:09:34 | 显示全部楼层
天啊,我要疯了,大家快来测试下吧。。。。
 楼主| 发表于 2008-4-13 23:24:42 | 显示全部楼层
control的代码

<?php

class blog extends Controller {

        function blog()
        {
                parent::Controller();
               
        }

        function index()
        {
                $this->load->model("testmodel");
                $data=$this->testmodel->getArr();
                $this->load->view('testview',$data);
        }
       
        function page($page)
        {
                $this->load->model("testmodel");
                $data=$this->testmodel->getArr();
                $this->load->view('testview',$data);
        }
}
?>


------------------------------

model的代码

<?php
class testmodel extends Model {

        function __construct()
        {
                parent::Model();
                $this->load->database();
        }

        function getArr()
        {
                $query = $this->db->query('SELECT id,username FROM citable');
                $row=$query->result_array();
                $data=array("username"=>$row["username"]);
                return $data;
        }
}
?>

--------------------
view的代码

<html>
<head>
<title>Blog</title>

<style type="text/css">

body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 16px;
font-weight: bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}

code {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}

</style>
</head>
<body>

<h1>Blog</h1>

<p><?=$username?></p>

</body>
</html>

-------------------------------------------------------------------

database.php的代码

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the "Database Connection"
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
|        ['hostname'] The hostname of your database server.
|        ['username'] The username used to connect to the database
|        ['password'] The password used to connect to the database
|        ['database'] The name of the database you want to connect to
|        ['dbdriver'] The database type. ie: mysql.  Currently supported:
                                 mysql, mysqli, postgre, odbc, mssql
|        ['dbprefix'] You can add an optional prefix, which will be added
|                                 to the table name when using the  Active Record class
|        ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
|        ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
|        ['cache_on'] TRUE/FALSE - Enables/disables query caching
|        ['cachedir'] The path to the folder where cache files should be stored
|        ['char_set'] The character set used in communicating with the database
|        ['dbcollat'] The character collation used in communicating with the database
|
| The $active_group variable lets you choose which connection group to
| make active.  By default there is only one group (the "default" group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "123456";
$db['default']['database'] = "cidb";
$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']['port'] = 3306;
?>
发表于 2008-4-13 23:25:08 | 显示全部楼层
经过我测试,没发现你说的问题,你可以上传你的代码,再看看。
发表于 2008-4-13 23:46:05 | 显示全部楼层
检查 MySQL 版本!!应该是你的版本太低了。

本版积分规则