I'm trying to get started with sqlite in the latest version of CodeIgniter.
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;
}
This gives me the following error: Fatal error: [] operator not supported for strings in / Applications / MAMP / htdocs / webites / api / public_html / system / database / DB_driver.php on line 1183
Or this error sometimes:
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
I've had the same issue when using CI 2.1.0 and found the following fix for the fatal error:
In system/database/DB_driver.php change:
Line 1165
$message = $error;
to
$message[] = $error;
Line 1169
$message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
to
$message[] = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
Source
Never tried to use SQLite with CI, but I found a possible answer to your problem. Try adding 'sqlite:' in front of your database name, like:
$db ['default'] ['database'] = 'sqlite:'.APPPATH.'db / producers.sqlite';
Source.
To solve the error "Fatal error: [] operator not supported for strings"
I modify file in *DB_driver.php:1171*
adding this line:
$message = (array)$message;
There is a bug in 2.1.0 preventing it from working with SQLite databases. You need to have updated version of CodeIgniter 2.1.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With