MySQL Data connection tutorial

Source: Internet
Author: User
Tags php script

MySQL Connection
Before you can do anything with MySQL PHP you must first establish a MySQL database connected to your Web page host. This is done with the MySQL connection feature.


MySQL localhost
If you have been around the Internet at the same time, you will know that IP addresses are used as identifiers for computers and Web servers. In this example of a connection script, we believe that the MySQL service is running on the same machine on the script.

When PHP scripts and MySQL are on the same machine, you can use the local address to connect to. Local is a shortcut, as long as the machine is connected to itself. If your MySQL service is running in a separate location, you need to insert the IP address or URL to replace the local. Please contact your web host for more details if the local is not working.

<?php
mysql_connect ("localhost", "admin", "1admin") or Die (Mysql_error ());
echo "Connected to mysql<br/>";
?>

Connected to MySQL

If you load the above PHP script into your Web server, everything works properly, then you should be able to see "Connect to MySQL" display when you view it. PHP page.

In the Mysql_connect function three arguments. Server, user name, and password. In our example above these arguments are:

Server-localhost
Username-admin

Password:1 Admin
That "or death (MySQL. .. "Code displays an error message if your browser-you may have guessed it-there is an error in processing the connection!" Carefully check your username, password or server if you receive this error.

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.