2014-01-08 41 views
0

我一直在努力寻找我现在做了几天错误的工作。我有一个ODBC连接建立一个辅助数据库,我严格选择数据。无法使Codeigniter ODBC与选择一起工作

因此,我知道连接正在工作,并且在活动记录中存在某些错误。这里是我的功能

public function get_pm_counts($date, $date_equal='<=') {  
    //connect to the history server 
    $this->histdb = $this->load->database('locator', true); 

    $query = "SELECT query_name, pmcount, entry_date, company_code, orig_system FROM (pmcounts) WHERE plant_code = '2970' AND entry_date = '01/07/2014' AND pmcount > 0"; 
    $result = odbc_exec($this->histdb->conn_id, $query); 
    echo '<pre>'; 
    while ($row = odbc_fetch_array($result)) 
    { 
     print_r($row);   
     echo '<br>'; 
    } 
    echo '</pre>'; 

    //run the query        
    $this->histdb 
     ->select('query_name, pmcount, entry_date, company_code, orig_system') 
     ->where('plant_code', '2970') 
     ->where('entry_date '.$date_equal, $date) 
     ->where('pmcount >', 0); 
    $query = $this->histdb->get('pmcounts'); 
    print_r($this->histdb->last_query()); 
    return $query; 
} 

显然函数的第一部分,我仅仅指刚运行的活动记录外的查询,然后我尝试用活动记录完全相同的查询。当我打印第一个查询时,在活动记录外,我返回我期望的结果。但运行的活动记录查询我得到如下当我打印$查询:

CI_DB_odbc_result Object 
(
[conn_id] => Resource id #8 
[result_id] => Resource id #10 
[result_array] => Array 
    (
    ) 

[result_object] => Array 
    (
    ) 

[custom_result_object] => Array 
    (
    ) 

[current_row] => 0 
[num_rows] => 0 
[row_data] => 
) 

------编辑------

当我打印$这个 - > histdb对象我得到以下内容:

CI_DB_odbc_driver Object 
(
[dbdriver] => odbc 
[_escape_char] => 
[_like_escape_str] => {escape '%s'} 
[_like_escape_chr] => ! 
[_count_string] => SELECT COUNT(*) AS 
[_random_keyword] => RND(1389212207) 
[ar_select] => Array 
    (
    ) 

[ar_distinct] => 
[ar_from] => Array 
    (
    ) 

[ar_join] => Array 
    (
    ) 

[ar_where] => Array 
    (
    ) 

[ar_like] => Array 
    (
    ) 

[ar_groupby] => Array 
    (
    ) 

[ar_having] => Array 
    (
    ) 

[ar_keys] => Array 
    (
    ) 

[ar_limit] => 
[ar_offset] => 
[ar_order] => 
[ar_orderby] => Array 
    (
    ) 

[ar_set] => Array 
    (
    ) 

[ar_wherein] => Array 
    (
    ) 

[ar_aliased_tables] => Array 
    (
    ) 

[ar_store_array] => Array 
    (
    ) 

[ar_caching] => 
[ar_cache_exists] => Array 
    (
    ) 

[ar_cache_select] => Array 
    (
    ) 

[ar_cache_from] => Array 
    (
    ) 

[ar_cache_join] => Array 
    (
    ) 

[ar_cache_where] => Array 
    (
    ) 

[ar_cache_like] => Array 
    (
    ) 

[ar_cache_groupby] => Array 
    (
    ) 

[ar_cache_having] => Array 
    (
    ) 

[ar_cache_orderby] => Array 
    (
    ) 

[ar_cache_set] => Array 
    (
    ) 

[ar_no_escape] => Array 
    (
    ) 

[ar_cache_no_escape] => Array 
    (
    ) 

[username] => hist**** 
[password] => ********* 
[hostname] => WMSlocator 
[database] => locator 
[dbprefix] => 
[char_set] => utf8 
[dbcollat] => utf8_general_ci 
[autoinit] => 1 
[swap_pre] => 
[port] => 
[pconnect] => 
[conn_id] => Resource id #10 
[result_id] => Resource id #11 
[db_debug] => 1 
[benchmark] => 0.1088068485 
[query_count] => 1 
[bind_marker] => ? 
[save_queries] => 1 
[queries] => Array 
    (
     [0] => SELECT query_name, pmcount, entry_date, company_code, orig_system 
FROM (pmcounts) 
WHERE plant_code = '2970' 
AND entry_date = '01/07/2014' 
AND pmcount > 0 
    ) 

[query_times] => Array 
    (
     [0] => 0.1088068485 
    ) 

[data_cache] => Array 
    (
    ) 

[trans_enabled] => 1 
[trans_strict] => 1 
[_trans_depth] => 0 
[_trans_status] => 1 
[cache_on] => 
[cachedir] => 
[cache_autodel] => 
[CACHE] => 
[_protect_identifiers] => 1 
[_reserved_identifiers] => Array 
    (
     [0] => * 
    ) 

[stmt_id] => 
[curs_id] => 
[limit_used] => 
[stricton] => 
) 

我看到查询时间为0.1秒,这是否意味着查询运行?让我真的很难弄清楚这一点,我不知道我在做什么错误的活动记录。我对codeigniter相当陌生。

谢谢尼克

回答

0

尝试echo $ query-> result();用途:

return $query->result(); 
+0

我得到一个空数组 – ninedoors

+0

你可能已经有了与正在使用的线日期的问题: - >在哪里(“ENTRY_DATE” $ date_equal,$日期)。我会建议从那里开始尝试解决这一问题。另外,检查最后一个查询与您的其他查询 – jco

+0

这不是它。我打印了$ this-> histdb-> last_query()并复制到第一个查询字符串。所以他们是完全一样的。但我只是在努力编写一个日期,并得到和以前一样的结果。感谢您的帮助。 – ninedoors

相关问题