<?php define(‘WXLEVELS_DB_HOST‘,‘127.0.0.1‘); //服务器 define(‘WXLEVELS_DB_USER‘,‘root‘); //数据库用户名 define(‘WXLEVELS_DB_PASS‘,‘123456‘); //数据库密码 define(‘WXLEVELS_DB_NAME‘,‘PvUv‘); //默认数据库 define(‘DB_CHARSET‘,‘utf8‘); //数据库字符集 define(‘TIMEZONE‘,"PRC"); //时区设置 class dataConn{ public function dataConn($host=WXLEVELS_DB_HOST ,$username=WXLEVELS_DB_USER,$password=WXLEVELS_DB_PASS,$dbname=WXLEVELS_DB_NAME) { $this->host = $host; $this->username = $username; $this->password = $password; $this->dbname = $dbname; } public function open() { $this->conn = mysql_connect($this->host,$this->username,$this->password) or die (‘数据库连接失败!</br>错误原因:‘.mysql_error()); mysql_select_db($this->dbname) or die(‘数据库选定失败!</br>错误原因:‘.mysql_error()); mysql_query("SET CHARACTER SET utf8"); } public function close() { mysql_close($this->conn); } }
PHP历程(PHP与MYSQL数据库之间连接、创建和关闭)
时间: 2024-10-12 02:05:38