php – Codeigniter insert_batch错误

我使用Codeigniter v2.1.4在sqlite3数据库中插入一些值.

问题是,当我尝试插入批处理时,它给出了一个错误:

>[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

如果我只插入一行就可以了.

这是有问题的查询:

INSERT INTO temp (Date, Name)
   Values("test","test2"),("test","test2"),("test","test2");

如果我用这个:

INSERT INTO temp (Date, Name) Values("test","test2");

它工作正常.

此外,如果我使用db-> insert(tablename,values)它可以正常工作,但如果我使用db-> insert_batch(tablename,array),我会得到上面提到的相同错误.

在一个单独的sqlite浏览器中,我可以在同一个数据库上执行上述查询而没有任何问题.

这是我在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;

这是数据库:

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)]);

使用print_r(array)后的数组如下所示:

[18-Jan-2014 10:20:04 UTC] Array
(
    [0] => Array
        (
            [Date] => test
            [Name] => test
        )

    [1] => Array
        (
            [Date] => test
            [Name] => test
        )
)

知道为什么会这样吗?
(不知怎的,我认为Codeigniter设置中存在问题,而不是查询本身,因为我在sqlite浏览器的同一数据库上使用了相同的查询,并且工作正常)

最佳答案 我已经将它作为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

点赞