/**
* 连接数据库
* @access public
* @return PDO
* @throws \Exception
*/
public function connect() {
if (!$this->pdo) {
try {
$this->pdo = new PDO($this->dsn, $this->username, $this->password, $this->params);
} catch (\PDOException $e) {
throw $e;
}
}
return $this->pdo;
}
/**
* 执行查询 返回数据集
*
* @param string $sql
* @param array $bind
* @param bool $cache
*
* @return array
* @throws \Exception
*/
public function query($sql, $bind = [], $cache = false) {
$items = null;
$dbCache = null;
if ($cache) {
/* @var $dbCache DBCache */
$dbCache = Ioc::get(DBCache::class);
$items = $dbCache->queryCache($sql, $bind);
}
if (!$items) {
$items = [];
$this->execute($sql, $bind, false);
$procedure = in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']);
trace调用栈
PDO->__construct(...)
rap\db\Connection->connect(...)
rap\db\Connection->execute(...)
rap\db\Connection->query(...)
rap\db\Select->findAll(...)
rap\db\Select->find(...)
rap\db\Record::find(...)
cloud\SiteConfig->handler(...)
rap\web\Application->start(...)
require(...)