简体   繁体   中英

Codeigniter insert_batch error

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)

我已经将它作为CodeIgniter 2.1.4问题发布在github上,并且我发现,“CI 2.1.4不支持SQLite3,2.1.x中的PDO驱动程序是实验性的,这意味着错误是预期的。完全SQLite3支持通过'sqlite3'和'pdo / sqlite'驱动程序可以在3.0-dev中找到“ - https://github.com/EllisLab/CodeIgniter/issues/2834#issuecomment-32838494

Because of

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.

I am going to guess that your array does not hold the keys for the columns in the database.

http://ellislab.com/codeigniter/user-guide/database/active_record.html#insert

It is hard to pin-point the exact problem without seeing more of the code.

我认为这是因为sqlite不支持这种查询,不确定codeigniter是否处理了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM