我正在尝试在最新版本的CodeIgniter中开始使用sqlite。
我的database.php如下所示:
$active_group = 'default';
$active_record = TRUE;
$db ['default'] ['hostname'] ='';
$db ['default'] ['username'] ='';
$db ['default'] ['password'] ='';
$db ['default'] ['database'] = APPPATH. 'db / producers.sqlite';
$db ['default'] ['dbdriver'] = 'sqlite';
$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;
我创建了我的表生成并将数据放入其中。
我正在尝试使用以下代码收集数据:
$query = $ this-> db-> get ('Producers');
foreach ($ query-> result () as $ row)
{
echo $ row-> name;
}
这给了我以下错误:Fatal error: [] operator not supported for strings in / Applications / MAMP / htdocs / webites / api / public_html / system / database / DB_driver.php on line 1183
或者有时会出现此错误:
A Database error occurred
Error Number: 1
SQL logic error or missing database
SELECT * FROM (Producers)
Filename: / Applications / MAMP / htdocs / webites / api / public_html / controllers / welcome.php
Line Number: 23
我该如何解决?我无法添加数据,也有类似的错误
答案 0 :(得分:2)
使用CI 2.1.0时遇到了同样的问题,并发现以下针对致命错误的修复:
在system / database / DB_driver.php中更改:
第1165行
$message = $error;
到
$message[] = $error;
第1169行
$message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
到
$message[] = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
答案 1 :(得分:1)
从未尝试过将SQLite与CI一起使用,但我找到了问题的可能答案。尝试在数据库名称前面添加“sqlite:”,例如:
$db ['default'] ['database'] = 'sqlite:'.APPPATH.'db / producers.sqlite';
答案 2 :(得分:1)
解决错误“致命错误:[]操作符不支持字符串”
我在* DB_driver.php中修改文件:1171 *
添加以下行:
$message = (array)$message;
答案 3 :(得分:1)
2.1.0中存在一个错误,阻止它使用SQLite数据库。您需要拥有CodeIgniter 2.1.1的更新版本。
答案 4 :(得分:0)
尝试codeigniter 3x
$db['default'] = array(
'dsn' => '',
'hostname' => 'sqlite:' . APPPATH . 'db/database.db',
'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
);