Working with SQLite in the encoder

I am trying to get started with sqlite in the latest version of CodeIgniter.

My database.php is as follows:

$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 created my table by creating and putting data into it.

I am trying to collect data using 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 solve it? I also can not add data, there are similar errors

+6
source share
5 answers

I had the same problem when using CI 2.1.0 and found the following fix for a fatal error:

In the variable system / database / DB_driver.php:

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; 

A source

+2
source

I never tried using SQLite with CI, but I found a possible answer to your problem. Try adding "sqlite:" in front of your database name, for example:

 $db ['default'] ['database'] = 'sqlite:'.APPPATH.'db / producers.sqlite'; 

Source

+1
source

To resolve the "Fatal error: operator [] is not supported for strings" error

I modify the file in * DB_driver.php: 1171 *

adding this line:

 $message = (array)$message; 
+1
source

In version 2.1.0 there is an error that prevents working with SQLite databases. You need to have an updated version of CodeIgniter 2.1.1.

+1
source

try 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 ); 
0
source

Source: https://habr.com/ru/post/902746/


All Articles