查询数据.select

函数原型

  1. public function select($mixData = null, $arrBind = [], $bFlag = false);

原生 sql 查询

  1. /*
  2. Array
  3. (
  4. [0] => select *from test where id = ?
  5. [1] => Array
  6. (
  7. [0] => 1
  8. )
  9. )
  10. */
  11. Db::table('test')->
  12. select('select *from test where id = ?', [1]);

直接查询 get

  1. /*
  2. Array
  3. (
  4. [0] => SELECT `test`.* FROM `test`
  5. [1] => Array
  6. (
  7. )
  8. [2] =>
  9. [3] => 5
  10. [4] =>
  11. [5] => Array
  12. (
  13. )
  14. )
  15. */
  16. Db::table('test')->
  17. select();

回调处理

  1. /*
  2. Array
  3. (
  4. [0] => SELECT `test`.* FROM `test` WHERE `test`.`id` = 1
  5. [1] => Array
  6. (
  7. )
  8. [2] =>
  9. [3] => 5
  10. [4] =>
  11. [5] => Array
  12. (
  13. )
  14. )
  15. */
  16. datas::table('test')->
  17. select(function($select) {
  18. $select->where('id', 1);
  19. });

参数为 Leevel\Database\Select

  1. /*
  2. Array
  3. (
  4. [0] => SELECT `test`.* FROM `test` WHERE `test`.`id` = 5
  5. [1] => Array
  6. (
  7. )
  8. [2] =>
  9. [3] => 5
  10. [4] =>
  11. [5] => Array
  12. (
  13. )
  14. )
  15. */
  16. $select = Db::table('test')->
  17. where('id', 5);
  18. Db::select($select);