在codeigniter中使用SQLite [英] Working with SQLite in codeigniter
问题描述
我想在最新版本的CodeIgniter中开始使用sqlite。
I'm trying to get started with sqlite in the latest version of CodeIgniter.
我的database.php看起来像这样:
My database.php looks like this:
$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;
我已经创建了我的表生成并放入数据。
I have created my table is produced and put data into it.
我试图使用此代码收集数据:
I'm trying to collect data with this code:
$query = $ this-> db-> get ('Producers');
foreach ($ query-> result () as $ row)
{
echo $ row-> name;
}
这会给我以下错误:致命错误: []运算符不适用于第1183行上/ Applications / MAMP / htdocs / webites / api / public_html / system / database / DB_driver.php中的字符串
或这个错误有时:
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
如何解决?我也无法添加数据,有类似的错误
How do I resolve it? I can not add data to either, there are similar errors
推荐答案
使用CI 2.1.0时,并发现了致命错误的以下修复:
I've had the same issue when using CI 2.1.0 and found the following fix for the fatal error:
在system / database / DB_driver.php中更改:
In system/database/DB_driver.php change:
第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;
这篇关于在codeigniter中使用SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!