我遇到了致命错误:本地问题。
$rr = $this->CI->db->query("select * from $table $condition ");
$mm = $rr->num_rows();
if ($mm>0) {
return 1;
} else {
return 0;
}
答案 0 :(得分:1)
<?php
$this->db->select("your stuff");
$query = $this->db->get("your table");
if($query->num_rows() > 0 ) {
return 1;
}
else {
return 0;
}
?>
答案 1 :(得分:0)
$this->CI->db->query("select * from $table $condition ");
删除CI和
$this->db->query("select * from $table $condition ");
答案 2 :(得分:0)
首先让你自动加载数据库
print(properties[0])
{"name": "Dummy Name","color": "#000000"}
如果您尝试加载库,请使用$ CI实例http://www.codeigniter.com/user_guide/general/ancillary_classes.html#get-instance
应用程序&gt;库&gt;使用example.php 强>
Publish
如果是模特
应用程序&gt;模型&gt; Example_model.php 强>
$autoload['libraries'] = array('database');
答案 3 :(得分:0)
更新一个CI核心文件并解决错误:
转到:系统/数据库/ 并修改 DB_active_rec.php 文件 转到第990行并查看打击代码
if ($query->num_rows() == 0)
{
return 0;
}
更新
if (!$query || $query->num_rows() == 0)
{
return 0;
}
希望解决了您的num_rows()
问题。
答案 4 :(得分:0)
类Site_m扩展了MY_Model {
protected $_table_name = 'setting';
protected $_primary_key = 'option';
protected $_primary_filter = 'intval';
protected $_order_by = "option asc";
function __construct() {
parent::__construct();
}
function get_site($id) {
$compress = array();
$query = $this->db->get('setting');
foreach ($query->result() as $row) {
$compress[$row->fieldoption] = $row->value;//here I am getting error
}
return (object) $compress;
}
}
/ *文件结束site_m.php * /
答案 5 :(得分:0)
这是核心 CI-2 中的修复 文件 \system\database\DB_driver.php
代码行 https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_driver.php#L659
在结束代码前替换 FALSE
// Run the Query
if (FALSE === ($this->result_id = $this->simple_query($sql)))
{
if ($this->save_queries == TRUE)
{
$this->query_times[] = 0;
}
// This will trigger a rollback if transactions are being used
$this->_trans_status = FALSE;
if ($this->db_debug)
{
// grab the error number and message now, as we might run some
// additional queries before displaying the error
$error_no = $this->_error_number();
$error_msg = $this->_error_message();
// We call this function in order to roll-back queries
// if transactions are enabled. If we don't call this here
// the error message will trigger an exit, causing the
// transactions to remain in limbo.
$this->trans_complete();
// Log and display errors
log_message('error', 'Query error: '.$error_msg);
return $this->display_error(
array(
'Error Number: '.$error_no,
$error_msg,
$sql
)
);
}
return FALSE;
}
到
// Run the Query
if (FALSE === ($this->result_id = $this->simple_query($sql)))
{
if ($this->save_queries == TRUE)
{
$this->query_times[] = 0;
}
// This will trigger a rollback if transactions are being used
$this->_trans_status = FALSE;
if ($this->db_debug)
{
// grab the error number and message now, as we might run some
// additional queries before displaying the error
$error_no = $this->_error_number();
$error_msg = $this->_error_message();
// We call this function in order to roll-back queries
// if transactions are enabled. If we don't call this here
// the error message will trigger an exit, causing the
// transactions to remain in limbo.
$this->trans_complete();
// Log and display errors
log_message('error', 'Query error: '.$error_msg);
return $this->display_error(
array(
'Error Number: '.$error_no,
$error_msg,
$sql
)
);
}
$CR = new CI_DB_result();
return $CR;
}
默认应该是返回对象为空
$CR = new CI_DB_result();
return $CR;