odbc num_rows codeigniter result_set为空

时间:2012-07-18 07:13:32

标签: php codeigniter odbc

我使用此代码验证用户。

public function verify_user($username, $password)
{
    $q = $this->db->where('username', $username)
        ->where('password', md5($password))
        ->limit(1)
        ->get('users');

    if ($q->num_rows() === 1) {
        echo '<pre>';
        print_r($q->row());
        echo '</pre>';
    } else {
        echo 'EMPTY';
    }
}

但是,当它等于1时,它什么都不显示。

Array
(
)

当我使用此代码修复odbc num_rows = -1问题时出现:{40}直到67 {/ 3}}

编辑=============================

我想要实现的是这个

stdClass Object
(
    [id_user] => 2
    [username] => 114080077
    [password] => 0d5ccab9e7f4ae3fe040f143046e386c
)

我修改的代码是: 之前(稳定版)

/**
 * Number of rows in the result set
 *
 * @access  public
 * @return  integer
 */
function num_rows()
{
    return @odbc_num_rows($this->result_id);
}

之后(ISSUE FIX)

/**
 * Number of rows in the result set
 *
 * @return  int
 */
public function num_rows()
{
    if (is_int($this->num_rows))
    {
        return $this->num_rows;
    }
    elseif (($this->num_rows = @odbc_num_rows($this->result_id)) !== -1)
    {
        return $this->num_rows;
    }

    // Work-around for ODBC subdrivers that don't support num_rows()
    if (count($this->result_array) > 0)
    {
        return $this->num_rows = count($this->result_array);
    }
    elseif (count($this->result_object) > 0)
    {
        return $this->num_rows = count($this->result_object);
    }

    return $this->num_rows = count($this->result_array());
}

3 个答案:

答案 0 :(得分:1)

if条件有错误,请使用:

$q->num_rows()

并尝试使用

$q->result()代替->row()

答案 1 :(得分:1)

通过用以下方法替换system / database / drivers / odbc / odbc_result.php来修复: Fix Issue

答案 2 :(得分:1)

您不能只使用CI_DB_odbc_result的开发版本,并保留2.1版本树中的其他内容。如果您不想替换所有这些,则需要从存储库获取的是以下文件:

system/database/DB_driver.php
system/database/DB_result.php
system/database/drivers/odbc/odbc_driver.php
system/database/drivers/odbc/odbc_result.php

(假设您只使用ODBC)

还有可能是ODBC结果类的问题,我会调查一下,但考虑到你的问题是指尚未发布的CodeIgniter版本 - 你发布会更好任何问题都会报告给CodeIgniter论坛或GitHub存储库。