- 25、显示最后一条查询的sql语句:主要用于在连贯操作时,检测拼接的sql语句是否正确
-
- echo $this->db->last_query();
- 26、CI_DB_pdo_driver PDO数据库驱动类
-
- $this->db->affected_rows();
-
- $this->db->count_all("order_master");
-
- $this->db->count_all_results();
-
- $this->db->insert_id();
-
- $this->db->trans_enabled = true;
-
- $this->db->trans_begin();
-
- $this->db->trans_rollback();
-
- $this->db->trans_commit();
-
- $this->db->trans_status();
- 27、CI_DB_mysql_driver mysql数据库驱动类
-
- $this->db->affected_rows();
-
- $this->db->count_all("order_master");
-
- $this->db->count_all_results();
-
- $this->db->insert_id();
-
- $this->db->trans_enabled = true;
-
- $this->db->trans_begin();
-
- $this->db->trans_rollback();
-
- $this->db->trans_commit();
-
- $this->db->trans_status();
- 28、CI_DB_mysqli_driver mysqli数据库驱动类
-
- $this->db->affected_rows();
-
- $this->db->count_all("order_master");
-
- $this->db->count_all_results();
-
- $this->db->insert_id();
-
- $this->db->trans_enabled = true;
-
- $this->db->trans_begin();
-
- $this->db->trans_rollback();
-
- $this->db->trans_commit();
-
- $this->db->trans_status();
- 29、model模型类中引用其它model模型类(如:category_model)和数据库(如:product)
-
- public function __construct() {
- parent::__construct();
- $this->product_db = $this->load->database('product', true);
- $this->load->model('category_model');
- }
- 30、控制器中引用其它模型类(如:category_model)和数据库(如:product)
-
- public function __construct() {
- parent::__construct();
- $this->product_db = $this->load->database('product', true);
- $this->load->model('category_model');
- }
- 31、helper函数中引用CI超级对象的方法
-
- function get_order_status_by_order($order_status){
-
- $CI =& get_instance();
-
- $CI->load->Model('order_model');
-
- }
- 32、缓存驱动的加载方式
-
- $this->load->driver('cache', array('adapter' => 'memcached'));
-
- $this->load->driver('cache', array('adapter' => 'file'));
-
- $this->load->driver('cache', array('adapter' => 'redis'));
-
- $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
- 33、静态html模板文件中如何动态加载区域块内容
-
-
- <div include="/index.php/pub/common_nav" rel="include"></div>
-
-
- $(document).ready(function () {
- $('[rel=\'include\']').each(function (e) {
- var t = $(this),
- url = t.attr('include') + location.search;
- url && $.get(url, function (data) {
- t.html(data);
- })
- })
- })
- 34、拼接insert sql语句
-
- function add_user( $data ) {
- if ( empty($data) || !is_array($data) ) {
- return false;
- }
- foreach ($data as $key => $value) {
- if ( $value === '') {
- unset($data[$key]);
- }
- }
- $cols = array_keys($data);
- $values = array_values($data);
- $cols_str = implode(",", $cols);
- $values_str = "'".implode("','", $values)."'";
-
- $sql = "INSERT INTO user ({$cols_str}) VALUES ({$values_str})";
- $this->db->query($sql);
- }
- 35、拼接insert sql语句
-
- function add_user( $data ) {
- if ( empty($data) || !is_array($data) ) {
- return false;
- }
- foreach ($data as $key => $value) {
- if ( $value === '') {
- unset($data[$key]);
- }
- }
- $cols = array_keys($data);
- $values = array_values($data);
- foreach($values as $k=>$val){
- $values[$k]="'".$val."'";
- }
- $cols_str = implode(",", $cols);
- $values_str = implode(",", $values);
-
- $sql = "INSERT INTO user ({$cols_str}) VALUES ({$values_str})";
- $this->db->query($sql);
- }
- 36、拼接update sql语句
-
- function edit_user(userid, $data) {
- if ( empty($data) || !is_array($data) ) {
- return;
- }
- foreach ($data as $key => $value) {
- $str .= isset($str)?", {$key} = '{$value}'":"{$key} = '{$value}'";
- }
-
- $sql = "UPDATE user SET {$str} WHERE addr_id = '{$addr_id}'";
- $this->db->query($sql);
- }
- 37、数据库快捷操作类常用方法
-
- public function get_order_list($query, $offset = 0, $limit = 20) {
- if (is_array($query) && !empty($query)) {
- foreach ($query as $key => $val) {
- if (is_array($val)) {
- $this->order_db->where_in($key, $val);
- } else {
- $this->order_db->where($key, $val);
- }
- }
- }
- $this->order_db->order_by('updatetime', 'desc');
- $this->order_db->order_by('id', 'desc');
- if (!$limit) {
- $query = $this->order_db->get('order');
- } else {
- $query = $this->order_db->get('order', $limit, $offset);
- }
-
- if ($query->num_rows() > 0) {
-
- return $query->result_array();
- }
-
- return array();
- }
- 38、拼接select sql语句
- function get_user_list($cols=array("username","password")) {
- $col=implode(",",$cols);
- $sql = "SELECT $col FROM user ORDER BY addr_id DESC";
- $this->db->query($sql)->result_array();
- }
- 39、CI框架中cookie的三种使用方式
-
-
- setcookie("user_id",$user_info['user_id'],86500);
- setcookie("username",$user_info['username'],86500);
- setcookie("password",$user_info['password'],86500);
-
-
-
- $this->input->set_cookie("username",$user_info['username'],60);
- $this->input->set_cookie("password",$user_info['password'],60);
- $this->input->set_cookie("user_id",$user_info['user_id'],60);
-
-
-
-
-
-
- set_cookie("username",$user_info['username'],60);
- set_cookie("password",$user_info['password'],60);
- set_cookie("user_id",$user_info['user_id'],60);
-
- 40、array_merge()合并数组函数的使用
- <?php
- header("content-type:text/html;charset='utf-8'");
- $arr1=array(
-
- "13012"=>array(
- "brand_id"=>2,
- "category_id"=>3
- )
-
- );
-
- $arr2=array(
-
- "13012"=>array(
- "goods_id"=>3576,
- "goods_name"=>"sanyang"
- )
-
- );
-
-
-
-
- ?>
- 41.json格式数据:
- public function json(){
- $data[0]['goods_id']=3567;
- $data[0]['goods_name']="sanyang";
- $data[1]['goods_id']=3567;
- $data[1]['goods_name']="sanyang";
- echo json_encode($data);exit;
-
- }
- 42.联合查询 left join
- $query = array(
- 'product_id' => $product_id,
- 'activity.status' => array(1, 2, 0),
- 'activity.is_del' => 0
- );
- $query['activity.activity_id<>'] = $activity_id;
-
- $goods_list = $this->activity_model->get_activity_good_mapping($query, 0, 0);
-
- public function get_activity_good_mapping($query,$offset = 0, $limit = 0,$get=''){
- $this->db = $this->activity_db;
- if (is_array($query) && !empty($query)) {
- foreach ($query as $key => $val) {
- if (is_array($val)) {
- $this->db->where_in($key, $val);
- } else {
- $this->db->where($key, $val);
- }
- }
- }
-
- $this->db->from('activity_goods');
- $this->db->join('activity', 'activity_goods.activity_id = activity.activity_id','left');
-
- if (!$limit) {
-
- } else {
- $query = $this->db->limit($limit, $offset);
- }
- $query = $this->db->get();
- if ($query->num_rows() > 0) {
-
- return $query->result_array();
- }
-
- return array();
- }
- 43.ci框架如何记录sql日志?
-
- (1)配置日志目录: 在"application/config/config.php" 文件中配置日志目录
- $config['log_path']="/opt/www/logs/";
- (2)在 "system/database/DB_driver.php" 文件的query()方法末尾添加如下语句:
- log_message( 'db','【sql语句:'.$this->last_query().'】');
- return $RES;
- public function get_record_count_by_condition($tablename,$condition,$likecondition,$cols){
- if(!empty($cols)){
- $this->db->select("count(*) as num");
- }else{
- $this->db->select("count(*) as num");
- }
- if (is_array($condition) && !empty($condition)) {
- foreach ($condition as $key => $val) {
- if (is_array($val)) {
- $this->db->where_in($key, $val);
- } else {
- $this->db->where($key, $val);
- }
- }
- }
-
- if (is_array($likecondition) && !empty($likecondition)) {
- foreach ($likecondition as $key => $val) {
- $this->db->like($key, $val);
- }
- }
-
- $num_info=$this-><span id="transmark"></span>db->get($tablename)->row_array();
- if($num_info['num'] > 0){
- return $num_info['num'];
- }else{
- return 0;
- }
- }
- foreach($content_list_temp_recommend as $k=>$v){
- $kk=array_search($v['aid'], $aid_arr_temp);
- $msg.=$aid_arr_temp[$kk].",";
- if($kk !== false){
- unset($aid_arr_temp[$kk]);
- }
- }
- $aid_arr= array_values($aid_arr_temp);
- $state = is_numeric($this->input->post('state', true)) ? $this->input->post('state', true):"";
- if(is_numeric($state)){
- $condition['state']=$state;
- }else{
- $state="";
- }
- $data['state']= (string)$state
- $this->load->view('content_list', $data);
-
-
- <td>
- <label>状态:</label>
- </td>
- <td>
- <select name="state" class="combox">
- <option value="" <?php if( "" ===$state)echo 'selected'?>>全部</option>
- <option value="0" <?php if("0" === $state)echo 'selected'?>>未审核</option>
- <option value="1" <?php if("1" === $state)echo 'selected'?>>已审核</option>
- </select>
- </td>
相关文章: