查询语言.sql

函数原型

本功能特别适合用于调试 SQL,大家可以这样子用。

  1. public function sql($bFlag = true);

用法如下

  1. /*
  2. Array
  3. (
  4. [0] => SELECT `test`.* FROM `test` ORDER BY `test`.`create_at` DESC LIMIT 1
  5. [1] => Array
  6. (
  7. )
  8. [2] =>
  9. [3] => 5
  10. [4] =>
  11. [5] => Array
  12. (
  13. )
  14. )
  15. */
  16. Db::table('test')->
  17. sql(true)->
  18. latest()->
  19. getOne();
  20. /*
  21. Array
  22. (
  23. [0] => delete from test where id = ?
  24. [1] => Array
  25. (
  26. [0] => 22
  27. )
  28. )
  29. */
  30. Db::sql(true)->
  31. delete('delete from test where id = ?', [22]);
  32. // 等效
  33. Db::delete('delete from test where id = ?', [22], true);

例外 getOne 等也支持快捷

  1. /*
  2. Array
  3. (
  4. [0] => SELECT `test`.* FROM `test` ORDER BY `test`.`create_at` DESC LIMIT 1
  5. [1] => Array
  6. (
  7. )
  8. [2] =>
  9. [3] => 5
  10. [4] =>
  11. [5] => Array
  12. (
  13. )
  14. )
  15. */
  16. Db::table('test')->
  17. latest()->
  18. getOne(true);
  19. /*
  20. public function select($strData, $arrBind = [], $bFlag = false);
  21. public function insert($mixData, $arrBind = [], $booReplace = false, $bFlag = false);
  22. public function insertAll($arrData, $arrBind = [], $booReplace = false, $bFlag = false);
  23. public function update($mixData, $arrBind = [], $bFlag = false);
  24. public function updateColumn($strColumn, $mixValue, $arrBind = [], $bFlag = false);
  25. public function updateIncrease($strColumn, $intStep = 1, $arrBind = [], $bFlag = false);
  26. public function updateDecrease($strColumn, $intStep = 1, $arrBind = [], $bFlag = false);
  27. public function delete($mixData = null, $arrBind = [], $bFlag = false);
  28. public function truncate($bFlag = false);
  29. public function statement($strData, $arrBind = [], $bFlag = false);
  30. public function getOne($bFlag = false);
  31. public function getAll($bFlag = false);
  32. public function get($nNum = null, $bFlag = false);
  33. public function value($strField, $bFlag = false);
  34. public function lists($mixFieldValue, $strFieldKey = null, $bFlag = false);
  35. public function getCount($strField = '*', $sAlias = 'row_count', $bFlag = false);
  36. public function getAvg($strField, $sAlias = 'avg_value', $bFlag = false);
  37. public function getMax($strField, $sAlias = 'max_value', $bFlag = false);
  38. public function getMin($strField, $sAlias = 'min_value', $bFlag = false);
  39. public function getSum($strField, $sAlias = 'sum_value', $bFlag = false);
  40. */