Home > php教程 > php手册 > 在 Codeigniter 中使用 sqlite3 数据库

在 Codeigniter 中使用 sqlite3 数据库

WBOY
Release: 2016-06-13 11:40:50
Original
1072 people have browsed it

在 Codeigniter 中使用 mysql 数据库是轻而易举的事情,只要在 <font face="NSimsun">application/config/database.php</font> 配置好数据库名称、帐号密码即可使用。

换成 sqlite 的话稍微麻烦点,Codeigniter 默认使用 PHP5 自带驱动来支持 sqlite 且该驱动只支持 sqlite 2.x 版本。好在从 Codeigniter 2.1 开始已经内置了 sqlite 的 pdo 驱动,通过 pdo 驱动就可以实现对 sqlite3 的支持。

编辑 <font face="NSimsun">application/config/database.php</font> 里的选项:

$db['default']['hostname'] = 'sqlite:' . FCPATH . '../db/tms.db';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'pdo';
$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;
Copy after login

这样就可以直接访问 sqlite 数据库了。

本文来源:芒果小站

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template