php框架

 首页 > php框架 > CodeIgniter数据库的使用

CodeIgniter数据库的使用

分享到:
【字体:
导读:
          载入database, $this-load-database(); 也可在config文件夹下的autoload.php文件中修改: $autoload[libraries] =array(database); 这样,就可以使用了。 查询单条数据: $this-db-select(title, content, date); $query=...

载入database,
 
$this->load->database();
也可在config文件夹下的autoload.php文件中修改:
$autoload['libraries'] =array('database');
这样,就可以使用了。
查询单条数据:
 
$this->db->select('title, content, date');
$query=$this->db->get_where('test',array('id'=>$id));
//$this->db->where('id', $id); 
//$query = $this->db->get('test');
return$query->row_array();
查询多条数据:
 
$this->db->select('title, content, date');
$query=$this->db->get('test');
//$this->db->from('test');
//$query = $this->db->get();
$this->db->order_by("title","desc"); 
return$query->result_array();
获取数据库中的记录总数:
 
$this->db->count_all(‘test');
$this->db->where('aid',$aid);
return$this->db->count_all_results('test');
 
分享到:
CodeIgniter框架备份数据库
导出txt格式: // Load the DB utility class $this->load->dbutil();    // Backup your entire database and assign it to a variable $backup=&$this->dbutil->backup(array('format'=>'txt'));     // Load the file helper and write the file to your server ...
CodeIgniter路由设置
在application/config/routes.php中添加路由规则。   $route['default_controller'] ='pages/view';//默认controller $route['(:any)'] ='pages/view/$1'; //(:num) 匹配数字 //(:any) 匹配任意字符 $route['products/([a-z]+)/(\d+)'] ="$1/i...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……