优惠券订单及其他脚本

DB_PDO.class.php 956B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * 数据库pdo连接
  4. */
  5. class DB_PDO{
  6. private static $pdo;
  7. private function __construct(){
  8. }
  9. /**
  10. * 获取实例化的PDO,单例模式
  11. * @return PDO
  12. */
  13. public static function getInstance($dbConf){
  14. if(!(self::$pdo instanceof PDO)){
  15. $dsn ="mysql:host=".$dbConf['host'].";port=".$dbConf['port'].";dbname=".$dbConf['dbName'];
  16. try {
  17. self::$pdo = new PDO($dsn,$dbConf['user'], $dbConf['password'], array(PDO::ATTR_PERSISTENT => true,PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); //保持长连接
  18. self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19. } catch (PDOException $e) {
  20. print "Error:".$e->getMessage()."<br/>";
  21. die();
  22. }
  23. }
  24. return self::$pdo;
  25. }
  26. }