Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 代码点火器Sqlite不工作_Php_Sql_Codeigniter_Sqlite - Fatal编程技术网

Php 代码点火器Sqlite不工作

Php 代码点火器Sqlite不工作,php,sql,codeigniter,sqlite,Php,Sql,Codeigniter,Sqlite,每当我在我的模型中这样查询我的数据库(sqlite)(我使用codeigniter,完整代码如下): 我得到以下错误: Fatal error: Call to a member function rowCount() on a non-object in /codeigniter/system/database/drivers/pdo/pdo_result.php on line 42 当将查询更改为不存在时,会出现“正确”错误,如: A Database Error Occurred Er

每当我在我的模型中这样查询我的数据库(sqlite)(我使用codeigniter,完整代码如下):

我得到以下错误:

Fatal error: Call to a member function rowCount() on a non-object in /codeigniter/system/database/drivers/pdo/pdo_result.php on line 42
当将查询更改为不存在时,会出现“正确”错误,如:

A Database Error Occurred
Error Number: HY000
no such column: posst
SELECT posst FROM posts
Filename: /codeigniter/models/post.php
Line Number: 8
这让我相信数据库确实在工作,但我缺少了一些东西。 我已尝试重新创建数据库。它实际上有一个表和一列,但我无法得到任何数据。我还尝试用不同的“管理”程序创建它,但没有效果。我确保它是一个SQLite3DB,根据phpinfo,它由Web服务器支持。 有人知道我哪里出错了吗

--------完整代码: models/post.php中的我的post模型

 <?php

class Post extends CI_Model{

    function get_posts(){

         $this->db->select('posst');
         $query = $this->db->get('posts');
         return $query->result_array();

        } 
}

对于
PDO
驱动程序,
CodeIgniter版本2.1.0
中有一个bug(他们刚刚在版本2.1.0中添加了PDO驱动程序)

您可以查看
版本2.1.1


请尝试升级您的CodeIgniter。

此修复的积分来自S.Stüvel、J.Bransen和S.Timmer。这是一个特定服务器的修复程序,所以YMMV。不过这对我来说很有帮助

在pdo_driver.php中,起始行81发生变化:

if(strpos($this->database, 'sqlite') !== FALSE) {
        $this->hostname = $this->database;
        $this->_random_keyword = ' RANDOM()';
    }
    else {
        $this->hostname .= ";dbname=".$this->database;
        $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
    }

    $this->trans_enabled = FALSE;
}

在第189行,将整个函数_execute($sql)更改为

然后在pdo_result.php中更改: 在线29更改

var $pdo_results = '';
var $pdo_index = 0;

第36行替换整个功能

function num_rows()
{
    if ( ! $this->pdo_results ) {
        $this->pdo_results = $this->result_id->fetchAll(PDO::FETCH_ASSOC);
    }
    return sizeof($this->pdo_results);
与:

然后在第60行换车

function num_fields()
{
    if ( is_array($this->pdo_results) ) {
        return sizeof($this->pdo_results[$this->pdo_index]);
    } else {
        return $this->result_id->columnCount();
    }
}
致:

然后在第94行更改:

function field_data()
{
    if ($this->db->db_debug)
    {
        return $this->db->display_error('db_unsuported_feature');
    }
    return FALSE;
}
然后第146行更改:

$this->pdo_index = $n;

然后在第159行换车

function _fetch_assoc()
{
    if ( is_array($this->pdo_results) ) {
        $i = $this->pdo_index;
        $this->pdo_index++;
        if ( isset($this->pdo_results[$i]))
            return $this->pdo_results[$i];
        return null;
    }
    return $this->result_id->fetch(PDO::FETCH_ASSOC);
}

最后在第174行更改:

function _fetch_object()
{
    if ( is_array($this->pdo_results) ) {
        $i = $this->pdo_index;
        $this->pdo_index++;
        if ( isset($this->pdo_results[$i])) {
            $back = new stdClass();
            foreach ( $this->pdo_results[$i] as $key => $val ) {
                $back->$key = $val;
            }
            return $back;
        }
        return null;
    }
    return $this->result_id->fetch(PDO::FETCH_OBJ);
}

这对我起了作用。同样,不是我的工作,而是S.Stüvel、J.Bransen和S.Timmer的功劳。
答案相当长,但我希望这会有所帮助。

我有Codeigniter 2.2.1,当我将application/config/database.php设置为与OP相同时,我可以使用sqlite数据库,有点。我可以创建新的数据库/文件,创建新的表并插入数据。问题是我无法读取任何数据

$query = $this->db->query("SELECT...");
返回空数组。执行此操作时也会发生同样的情况

显然仍然存在一些bug。我刚刚开始探索Codeigniter,但是当我切换到mysql时,相同的模型会正常工作


作为记录,我的服务器上的一切都设置得很好。我可以很好地使用我的sqlite数据库,只是Codeigniter有问题。

我在从2.1.3更新到2.2.6后应用了g_m解决方案,作为jimmy,我不得不删除pdo_driver.php中的第一个更改以使其正常工作。

请提供完整的代码。确定添加了所有相关的代码吗使用最新的CodeIgniter?是的,我从githubIn
数据库中克隆了2.1稳定版。php
,尝试将dbdriver从
pdo
更改为
sqlite
,我只是进行了双重检查,因为我是从github克隆的,但我已经在2.1.4上了,但我必须撤消第一个更改:-“在pdo_driver.php中,开始行81更改:”
function num_rows()
{
    if ( ! $this->pdo_results ) {
        $this->pdo_results = $this->result_id->fetchAll(PDO::FETCH_ASSOC);
    }
    return sizeof($this->pdo_results);
function num_fields()
{
    return $this->result_id->columnCount();
}
function num_fields()
{
    if ( is_array($this->pdo_results) ) {
        return sizeof($this->pdo_results[$this->pdo_index]);
    } else {
        return $this->result_id->columnCount();
    }
}
function field_data()
{
    $data = array();

    try
    {
        for($i = 0; $i < $this->num_fields(); $i++)
        {
            $data[] = $this->result_id->getColumnMeta($i);
        }

        return $data;
    }
    catch (Exception $e)
    {
        if ($this->db->db_debug)
        {
            return $this->db->display_error('db_unsuported_feature');
        }
        return FALSE;
    }
}
function field_data()
{
    if ($this->db->db_debug)
    {
        return $this->db->display_error('db_unsuported_feature');
    }
    return FALSE;
}
return FALSE;
$this->pdo_index = $n;
function _fetch_assoc()
{
    return $this->result_id->fetch(PDO::FETCH_ASSOC);
}
function _fetch_assoc()
{
    if ( is_array($this->pdo_results) ) {
        $i = $this->pdo_index;
        $this->pdo_index++;
        if ( isset($this->pdo_results[$i]))
            return $this->pdo_results[$i];
        return null;
    }
    return $this->result_id->fetch(PDO::FETCH_ASSOC);
}
function _fetch_object()
{   
    return $this->result_id->fetchObject();
function _fetch_object()
{
    if ( is_array($this->pdo_results) ) {
        $i = $this->pdo_index;
        $this->pdo_index++;
        if ( isset($this->pdo_results[$i])) {
            $back = new stdClass();
            foreach ( $this->pdo_results[$i] as $key => $val ) {
                $back->$key = $val;
            }
            return $back;
        }
        return null;
    }
    return $this->result_id->fetch(PDO::FETCH_OBJ);
}
$query = $this->db->get('table_name');
return $query->result_array();
$query = $this->db->query("SELECT...");