Connection to the php-database

Source: Internet
Author: User

conn.php

1<?PHP2 //1, connect the database mysql_connect (' Database address ', ' username ', ' password '), as long as the connection is successful will return a resource type, connection failure, return false3 $link=mysql_connect(' localhost ', ' root ', ' 123321 ');4 if(!$link){5     //connection failure, error, interrupt program (die), die often used in production environments, usually when the program is not expected to meet the results of the use of6      die(Mysql_error());7     //Exit Quit program exit, usually for debugging8 }9 //2. Select Database mysql_select_db (' database name ')Ten if(!mysql_select_db(' Test ')){ One      die(' NO FOUND DB '); A } - //3, set the transmission code for UTF8, in order to prevent garbled: 1, the database encoding must be utf8,2, database connection settings UTF8 transmission encoding, 3, the page encoding must be UTF8 - mysql_query(' Set names UTF8 '); the Mysql_close();//Close the connection, you can ignore -?>

Connection to the php-database

Related Article

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.