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.