Db.Class.php 903 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Mall\Framework\Core;
  3. class Db
  4. {
  5. static protected $instance;
  6. static public function getInstance($options = [])
  7. {
  8. $options = $options ?: Config::getInstance()->get('db');
  9. $options['driver'] = strtolower($options['driver']);
  10. $key = $options['driver'] . md5(implode(',', $options));
  11. if (!isset(self::$instance[$key])) {
  12. switch ($options['driver'])
  13. {
  14. case 'mssql':
  15. $class = 'Mall\\Framework\\Db\\DbMssql';
  16. break;
  17. case 'oci':
  18. $class = 'Mall\\Framework\\Db\\DbOci';
  19. break;
  20. default:
  21. $class = 'Mall\\Framework\\Db\\Db';
  22. break;
  23. }
  24. self::$instance[$key] = new $class($options);
  25. }
  26. return self::$instance[$key];
  27. }
  28. }