I use Codeigniter v2.1.4 to insert some values in a sqlite3 database.
The problem is that when I try to insert a batch it gives me an error:
>[17-Jan-2014 22:44:17 UTC] PHP Fatal error: Call to a member function execute() on a >non-object in E:\Repository\cashy-support-app2\system\database\drivers\pdo\pdo_driver.php >on line 193
>[17-Jan-2014 22:44:17 UTC] PHP Stack trace:
>[17-Jan-2014 22:44:17 UTC] PHP 1. {main}() E:\Repository\cashy-support-app2\index.php:0
>[17-Jan-2014 22:44:17 UTC] PHP 2. require_once() E:\Repository\cashy-support-app2\index.php:202
>[17-Jan-2014 22:44:17 UTC] PHP 3. call_user_func_array() E:\Repository\cashy-support-app2\system\core\CodeIgniter.php:359
>[17-Jan-2014 22:44:17 UTC] PHP 4. Main_controller->index() E:\Repository\cashy-support-app2\system\core\CodeIgniter.php:359
>[17-Jan-2014 22:44:17 UTC] PHP 5. Favorites_Model->addToTemp() E:\Repository\cashy-support-app2\application\controllers\main_controller.php:7
>[17-Jan-2014 22:44:17 UTC] PHP 6. CI_DB_driver->query() E:\Repository\cashy-support-app2\application\models\favorites_model.php:106
>[17-Jan-2014 22:44:17 UTC] PHP 7. CI_DB_driver->simple_query() E:\Repository\cashy-support-app2\system\database\DB_driver.php:299
>[17-Jan-2014 22:44:17 UTC] PHP 8. CI_DB_pdo_driver->_execute() E:\Repository\cashy-support-app2\system\database\DB_driver.php:453
If I insert only one row it works ok.
This is the problematic query:
INSERT INTO temp (Date, Name)
Values("test","test2"),("test","test2"),("test","test2");
If I use this:
INSERT INTO temp (Date, Name) Values("test","test2");
it works ok.
Also if I use db->insert(tablename, values) it works ok, but if I use db->insert_batch(tablename, array), I get the same error mentioned above.
In a separate sqlite browser i can execute the above querys on the same database without any problem.
Here is my database config in Codeigniter:
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = 'sqlite:'.APPPATH.'db/Support_Mails.db';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';//APPPATH.'db/Support_Mails.db';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = APPPATH.'cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
This is the database:
CREATE TABLE [temp] (
[Date] [TEXT(255)],
[Name] [TEXT(255)],
[Mail] [TEXT(255)],
[Subject] [TEXT(255)],
[Conversation] [TEXT(255)],
[Language] [TEXT(255)],
[Body] [TEXT(30000)],
[ROWID] [TEXT(255)],
[TableName] [TEXT(255)],
[userid] [TEXT(255)]);
the array after using print_r(array) looks like this:
[18-Jan-2014 10:20:04 UTC] Array
(
[0] => Array
(
[Date] => test
[Name] => test
)
[1] => Array
(
[Date] => test
[Name] => test
)
)
Any idea why it does that? (Somehow i think that there is a problem in the Codeigniter setup, not in the query itself because i used the same query on the same database with an sqlite browser and it works ok)