<?PHP/*The default database is test, the data table is admin, the administrator only need to modify DB_PWD (that is, the local server password), the user password with MD5 encryption*/Define(Db_host, "localhost");Define(Db_user, "root");Define(Db_pwd, "Yuyouwen");Define(Db_name, "test");$con=mysql_connect(DB_HOST,DB_USER,DB_PWD) or die("Unable to connect to database server!") ");mysql_select_db(Db_name,$con);//Create Databaseif(!mysql_select_db(Db_name,$con)) { mysql_query("CREATE DATABASE test"); if(mysql_select_db(Db_name,$con)){ $query="CREATE Table admin (' ID ' smallint (5) NOT NULL auto_increment, ' username ' varchar (+) NOT NULL, ' Password ' varchar NOT NULL, ' email ' varchar (+) NOT null, ' regtime ' varchar (+) NOT NULL, PRIMARY KEY (' id '))"; mysql_query($query); } }?>
Note that in CREATE database, the data table must be established after the decision mysql_select_db(db_name,$con) , that is, the connection to the database has been successful.
PHP verifies whether the database is established, no, then automatically establishes