The fourth day of learning php in ten days

Source: Internet
Author: User

 

Objective: To learn how to connect to a database

PHP is simply a function library. Rich functions make some parts of PHP quite simple. We recommend that you use a PHP function manual.

Let me briefly talk about connecting to the MYSQL database.

1. mysql_connect

Open the MySQL server connection.
Syntax: int mysql_connect (string [hostname] [: port], string [username], string [password]); Return Value: integer

This function establishes a connection with the MySQL server. All parameters can be omitted. When you use this function without adding any parameters, the default value of the hostname parameter is localhost, the default value of the username parameter is the owner of the PHP route execution, and the parameter password is a null string (that is, no password ). The hostname parameter can be followed by a colon and a port number, indicating which port is used to connect to MySQL. Of course, when using the database, you can use mysql_close () to turn off the connection earlier to save resources.

2. mysql_select_db

Select a database.
Syntax: int mysql_select_db (string database_name, int [link_identifier]); Return Value: integer

This function selects a database on the MySQL server for subsequent data query job (query) processing. True is returned for success, and false is returned for failure.

The simplest example is:
$ Conn = mysql_connect ("127.0.0.1 ","","");
Mysql_select_db ("shop ");
Connect to my SQL database and open the SHOP database. In practical applications, we should strengthen the judgment of point errors.

Let's talk about this today. Let's talk about database reading tomorrow.

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.