2014-01-08 45 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

相關問題