{{info}}
{{msg}}
  
  1. $this->PDOStatement = null;
  2. if ($clear_cache) {
  3. /* @var $dbCache DBCache */
  4. $dbCache = Ioc::get(DBCache::class);
  5. $dbCache->deleteCache($sql);
  6. }
  7. try {
  8. // 调试开始
  9. // 预处理
  10. $this->PDOStatement = $pdo->prepare($sql);
  11. // 参数绑定
  12. $this->bindValue($bind);
  13. // 执行查询
  14. $this->PDOStatement->execute();
  15. } catch (\PDOException $e) {
  16. $error = $e->errorInfo;
  17. //2006和2013表示表示连接失败,需要重连接
  18. if ($error[ 1 ] == 2006 || $error[ 1 ] == 2013) {
  19. $this->pdo = null;
  20. $this->connect();
  21. $this->execute($sql, $bind);
  22. } else {
  23. throw $e;
  24. }
  25. }
  26. }
  27. /**
  28. * 切换数据库
  29. *
  30. * @param string $db
  31. */
  32. public function userDb($db) {
  33. $pdo = $this->connect();
  34. // 根据参数绑定组装最终的SQL语句
  35. try {
  36. $pdo->exec("use " . $db);
  37. } catch (\PDOException $e) {
  38. $error = $e->errorInfo;
trace调用栈
    
  1. PDO->prepare(...)
  2. rap\db\Connection->execute(...)
  3. rap\db\Connection->query(...)
  4. rap\db\Select->findAll(...)
  5. rap\db\Select->find(...)
  6. rap\db\Record::find(...)
  7. cloud\SiteConfig->handler(...)
  8. rap\web\Application->start(...)
  9. require(...)