PHP verifies whether the database is established, no, then automatically establishes

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.