{{info}}
{{msg}}
  
  1. /**
  2. * 连接数据库
  3. * @access public
  4. * @return PDO
  5. * @throws \Exception
  6. */
  7. public function connect() {
  8. if (!$this->pdo) {
  9. try {
  10. $this->pdo = new PDO($this->dsn, $this->username, $this->password, $this->params);
  11. } catch (\PDOException $e) {
  12. throw $e;
  13. }
  14. }
  15. return $this->pdo;
  16. }
  17. /**
  18. * 执行查询 返回数据集
  19. *
  20. * @param string $sql
  21. * @param array $bind
  22. * @param bool $cache
  23. *
  24. * @return array
  25. * @throws \Exception
  26. */
  27. public function query($sql, $bind = [], $cache = false) {
  28. $items = null;
  29. $dbCache = null;
  30. if ($cache) {
  31. /* @var $dbCache DBCache */
  32. $dbCache = Ioc::get(DBCache::class);
  33. $items = $dbCache->queryCache($sql, $bind);
  34. }
  35. if (!$items) {
  36. $items = [];
  37. $this->execute($sql, $bind, false);
  38. $procedure = in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']);
trace调用栈
    
  1. PDO->__construct(...)
  2. rap\db\Connection->connect(...)
  3. rap\db\Connection->execute(...)
  4. rap\db\Connection->query(...)
  5. rap\db\Select->findAll(...)
  6. rap\db\Select->find(...)
  7. rap\db\Record::find(...)
  8. cloud\SiteConfig->handler(...)
  9. rap\web\Application->start(...)
  10. require(...)