<?php /** * CodeIgniter 的測試 Model * * CodeIgniter 輸出 sql 語句代碼是: * $this->db->last_query() */ class TestModel extends CI_Model { private $table = 'DBTable'; public function index() { $year = $this->input->post('year'); $month = $this->input->post('month'); $day = $this->input->post('day'); $this->load->database(); $result = $this->db ->select('*') ->from($this->table) ->where('year', $year) ->where('month', $month) ->where('day', $day) ->order_by('sort', 'DESC') ->get() ->rerult(); // 檢查 sql 語句代碼 $this->sqlout(__LINE__); return $result; } /* 功能:文件輸出 sql 語句代碼,用於測試 * * 調用方式:在查詢構造器下方輸入如下代碼 * $this->sqlout(); * * 生成的文件目錄:\application\models * 文件名:ClassName_line_sql.txt */ public function sqlout($line) { $testSql = $this->db->last_query(); if(isset($testSql)){ $sql = json_decode(str_replace('\n', ' ', json_encode($testSql))); file_put_contents(__DIR__.'/'.__CLASS__.'_'.$line.'_sql.txt', $sql); } } }
codeIgniter 跳轉:redirect(‘signIn/index’);
php 換行符:PHP_EOL