dpxpz37157 2016-05-06 19:07
浏览 46
已采纳

CodeIgniter 3.0.6中的SQLite3

I can't find any documentation on how to use sqlite3 in CodeIgniter, but it does say that it is supported.

Here is my current database configuration:

$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = 'db/base.db';
$db['default']['dbdriver'] = 'sqlite3';
$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;

But I get a very undescriptive error on page load

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

Filename: core/CodeIgniter.php

Line Number: 500

So my question is, why is my config not working, and how can I make it work?

  • 写回答

2条回答 默认 最新

  • dtzd65908 2016-05-07 13:09
    关注

    You are using CI2 syntax, I don't know where you got it as in default package you can find the same code as below, where only thing you need to define is database (path to db) and dbdriver

    $db['default'] = array(
        'dsn'      => '',
        'hostname' => '',
        'username' => '',
        'password' => '',
        'database' => './application/database/data.db',
        'dbdriver' => 'sqlite3',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
    

    Or you can use this (with PDO database driver which requires dsn string, otherwise CI will try to build it)

    $db['default'] = array(
        'dsn'      => 'sqlite:application/database/data.db',// path/to/database
        'hostname' => '',
        'username' => '',
        'password' => '',
        'database' => '',
        'dbdriver' => 'pdo',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效