$this->PDOStatement = null;
if ($clear_cache) {
/* @var $dbCache DBCache */
$dbCache = Ioc::get(DBCache::class);
$dbCache->deleteCache($sql);
}
try {
// 调试开始
// 预处理
$this->PDOStatement = $pdo->prepare($sql);
// 参数绑定
$this->bindValue($bind);
// 执行查询
$this->PDOStatement->execute();
} catch (\PDOException $e) {
$error = $e->errorInfo;
//2006和2013表示表示连接失败,需要重连接
if ($error[ 1 ] == 2006 || $error[ 1 ] == 2013) {
$this->pdo = null;
$this->connect();
$this->execute($sql, $bind);
} else {
throw $e;
}
}
}
/**
* 切换数据库
*
* @param string $db
*/
public function userDb($db) {
$pdo = $this->connect();
// 根据参数绑定组装最终的SQL语句
try {
$pdo->exec("use " . $db);
} catch (\PDOException $e) {
$error = $e->errorInfo;
trace调用栈
PDO->prepare(...)
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(...)