PHP link MySQL code test

Source: Internet
Author: User
Tags mysql code mysql host

PHP connection MySQL is the first step in the database operation, in PHP, you can use the built-in PHP function mysql_connect () to implement, the function format is mysql_connect ("MySQL hostname", "MySQL User name", "MySQL password" ), the following test code can test for a successful connection to MySQL:

<?php$conn = mysql_connect ("localhost", "root", "pass") or Die ("Connect err:". Mysql_error ()); echo "MySQL database succeeded! ";? >

In the test code above: Assuming that the MySQL host name is native localhost, the username and password are root, subject to your actual hostname and user name password, the Die function is intended to terminate the program when the MySQL connection fails and to output the cause of the error.



This article is from the "Operation and maintenance House (Q Group: 1991706)" blog, please be sure to keep this source http://304076020.blog.51cto.com/7503470/1571723

PHP link MySQL code test

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.