我一直在努力试图找出我现在做错了几天。我有一个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;
}
显然,函数的第一部分我是jsut在活动记录之外运行查询然后我尝试使用活动记录完全相同的查询。当我打印第一个查询,外部活动记录时,我返回我期望的结果。但是当我打印$ 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] =>
)
------编辑------
当我打印$ this-&gt; 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 :(得分:0)
尝试回显$ query-&gt; result();并使用:
return $query->result();