支持标前缀
1)查询不等于且有等于
[php] view plain copy
$this->db->get_where('host',array('host'=>'ddd','id !='=>0))->row()
2)2表相交
[php] view plain copy
return $this->db
->select('f.*,count(s.id) as subtotal')
->from('category as f')->join('category s', 'f.id=s.upid', 'left')
->where('f.upid', $upid)
->group_by('f.id')
->order_by('f.sort', 'asc')
->get()->result()
3)多个order_by 排序
[php] view plain copy
return $this->db->select('*')
->from('v_category')
->where('upid',$upid)
->order_by('sort','asc')
->order_by('id','desc')
->get()->result()
4)单条记录
[php] view plain copy
return $this->db->get_where('category', array('id' =>$id))->row()
5)多条记录
[php] view plain copy
return $this->db->get_where('v_category', array('upid' =>$upid))->result()
6)统计个数
[php] view plain copy
$this->db->where('host',$host)->where('id !=',$id)->from('host')->count_all_results()
首先CodeIgniter连接数据库连不上,总是显示连接错误,但是又没有error信息,难以debug。解决方案是:在application/config/database.php文件的最后加上这一段代码:
复制代码
代码如下:
echo
'<pre>'
print_r($db['default'])
echo
'</pre>'
echo
'Trying
to
connect
to
database:
'
.$db['default']['database']
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or
die('Cannot
connect
to
the
database
because:
'
.
mysql_error())
mysql_select_db
($db['default']['database'])
echo
'<br
/>
Connected
OK:'
die(
'file:
'
.__FILE__
.
'-->
Line:
'
.__LINE__)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)