php基础教程--数据库连接及登录注册
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Login Page</title><link rel="shortcut icon" href="/favicon.ico"><link rel="stylesheet" type="text/css" href="js/style.css" /></head><body><?php $username = $_POST['username'];$passwords = $_POST['password'];if(is_null($username)||is_null($passwords)){echo "请确定用户名和密码都已填写";}else {$sql="select 'name','password' from userlist where name='".$username."'and password = '".$passwords."'";}class DataBase{public $dbhost = "localhost";public $dbuser = "root";public $dbpass = "123456";public $dbname = "test";function conn(){$dbconn = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die("database error!".mysql_error());mysql_select_db($this->dbname) or die("can not connect database:".mysql_error());return $dbconn;}function indb($in_sql){$result_indb = mysql_query($insql) or die("can not run the sql language$insql:".mysql_error());return $result_indb;}}$db = new DataBase();$db->conn();echo $db->indb($sql);?><br /><br /><br /><br /><br /><br /></body></html>