1、CI_DB_mysql_driver 继承CI_DB, CI_DB这个类是不存在的,每次调用文件中~/CodeIgniter_2.1.3/system/database/DB.php函数DB来初始化database的时候, 根据用户是否开启active_record,生成继承CI_DB_active_record或CI_DB_driver类的CI_DB类, 2、CI_DB_a
1、ci_db_mysql_driver 继承 ci_db, ci_db这个类是不存在的,每次调用文件中~/codeigniter_2.1.3/system/database/db.php函数&db来初始化database的时候,
根据用户是否开启active_record,生成继承CI_DB_active_record或CI_DB_driver类的CI_DB类,
2、CI_DB_active_record类继承CI_DB_driver类
<span>require_once</span>(BASEPATH.'database/DB_driver.php'<span>);
</span><span>if</span> ( ! <span>isset</span>(<span>$active_record</span>) OR <span>$active_record</span> == <span>TRUE</span><span>)
{
</span><span>require_once</span>(BASEPATH.'database/DB_active_rec.php'<span>);
</span><span>if</span> ( ! <span>class_exists</span>('CI_DB'<span>))
{
</span><span>eval</span>('class CI_DB extends CI_DB_active_record { }'<span>);
}
}
</span><span>else</span><span>
{
</span><span>if</span> ( ! <span>class_exists</span>('CI_DB'<span>))
{
</span><span>eval</span>('class CI_DB extends CI_DB_driver { }'<span>);
}
}</span>3、最终会调用顶级父类CI_DB_driver的构造方法,将数据库配置的各字段赋值到CI_DB_driver类的各个字段上,
<span>$active_group</span> = 'default'<span>;
</span><span>$active_record</span> = <span>TRUE</span><span>;
</span><span>$db</span>['default']['hostname'] = 'localhost'<span>;
</span><span>$db</span>['default']['username'] = ''<span>;
</span><span>$db</span>['default']['password'] = ''<span>;
</span><span>$db</span>['default']['database'] = ''<span>;
</span><span>$db</span>['default']['dbdriver'] = 'mysql'<span>;
</span><span>$db</span>['default']['dbprefix'] = ''<span>;
</span><span>$db</span>['default']['pconnect'] = <span>TRUE</span><span>;
</span><span>$db</span>['default']['db_debug'] = <span>TRUE</span><span>;
</span><span>$db</span>['default']['cache_on'] = <span>FALSE</span><span>;
</span><span>$db</span>['default']['cachedir'] = ''<span>;
</span><span>$db</span>['default']['char_set'] = 'utf8'<span>;
</span><span>$db</span>['default']['dbcollat'] = 'utf8_general_ci'<span>;
</span><span>$db</span>['default']['swap_pre'] = ''<span>;
</span><span>$db</span>['default']['autoinit'] = <span>TRUE</span><span>;
</span><span>var</span> <span>$username</span><span>;
</span><span>var</span> <span>$password</span><span>;
</span><span>var</span> <span>$hostname</span><span>;
</span><span>var</span> <span>$database</span><span>;
</span><span>var</span> <span>$dbdriver</span> = 'mysql'<span>;
</span><span>var</span> <span>$dbprefix</span> = ''<span>;
</span><span>var</span> <span>$char_set</span> = 'utf8'<span>;
</span><span>var</span> <span>$dbcollat</span> = 'utf8_general_ci'<span>;
</span><span>var</span> <span>$autoinit</span> = <span>TRUE</span><span>;
</span><span>var</span> <span>$port</span> = ''<span>;
</span><span>var</span> <span>$pconnect</span> = <span>FALSE</span><span>;
</span><span>var</span> <span>$db_debug</span> = <span>FALSE</span>;
如果autoinit自动初始化为TRUE,则将DB初始化,这个DB对象是CI_DB_mysql_driver类
<span> require_once</span>(BASEPATH.'database/DB_driver.php'<span>);
</span><span>if</span> ( ! <span>isset</span>(<span>$active_record</span>) OR <span>$active_record</span> == <span>TRUE</span><span>)
{
</span><span>require_once</span>(BASEPATH.'database/DB_active_rec.php'<span>);
</span><span>if</span> ( ! <span>class_exists</span>('CI_DB'<span>))
{
</span><span>eval</span>('class CI_DB extends CI_DB_active_record { }'<span>);
}
}
</span><span>else</span><span>
{
</span><span>if</span> ( ! <span>class_exists</span>('CI_DB'<span>))
{
</span><span>eval</span>('class CI_DB extends CI_DB_driver { }'<span>);
}
}
</span><span>require_once</span>(BASEPATH.'database/drivers/'.<span>$params</span>['dbdriver'].'/'.<span>$params</span>['dbdriver'].'_driver.php'<span>);
</span><span>//</span><span> Instantiate the DB adapter</span>
<span>$driver</span> = 'CI_DB_'.<span>$params</span>['dbdriver'].'_driver'<span>;
</span><span>$DB</span> = <span>new</span> <span>$driver</span>(<span>$params</span><span>);
</span><span>if</span> (<span>$DB</span>->autoinit == <span>TRUE</span><span>)
{
</span><span>$DB</span>-><span>initialize();
}
</span><span>return</span> <span>$DB</span>;
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号