class MysqlConn { public $dbtype; public $host; public $dbname; public $user; public $pwd; function __construct($dbtype,$dbname,$host,$user,$pwd) { $this->dbtype=$dbtype; $this->host=$host; $this->dbname=$dbname; $this->user=$user; $this->pwd=$pwd; if($this->dbtype=="mysql" || $this->dbtype=="mssql") { $dsn="$this->dbtype:host=$this->host;dbname=$this->dbname"; } else { $dsn="$this->dbtype:dbname=$this->dbname"; } try { $conn = new PDO($dsn, $this->user, $this->pwd); //初始化一个PDO对象,就是创建了数据库连接对象$pdo $conn->query("set names utf8"); return $conn; } catch(PDOException $e) { die("Error!: " . $e->getMessage() . "<br/>"); } } } $conn=new MysqlConn("mysql","dzxx_db","localhost","admin","123");//数据库连接类实例化,执行连接操作,返回连接标识
天使之翼死神之镰
错过了年华