Mysql Data Connection tutorial

Source: Internet
Author: User

MySQL connection before you can do anything with MySQL PHP, you must first establish a MySQL database connected to your web host. This is the connection function with MySQL.

MySQL connection
Before you can do anything with MySQL PHP, you must first create a MySQL database to connect to your web host. This is the connection function with MySQL.


MySQL localhost
If you are always on the internet, you will know that IP addresses are used as identifiers for computers and network servers. In this example, we assume that MySQL services are running scripts on the same machine.

When the PHP script and MySQL are on the same machine, you can use the local address to connect. 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 an IP address or URL to replace local. Please contact your web host for more details, if not working locally.

<? Php
Mysql_connect ("localhost", "admin", "1 admin") or die (mysql_error ());
Echo "Connected to MySQL <br/> ";
?>

Connected to MySQL

If you load the above PHP script to your web server, everything works normally, then you should see "connect to MySQL" display when you view. PHP page.

There are three arguments in the mysql_connect function. Server, user name, and password. In our example, the above arguments are:

Server-localhost
Username-admin

Password: 1 admin
The "or death (mysql..." code displays an error message if your browser-you may have guessed-there is an error in processing the connection! Check your username, password, or server carefully 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.