Learning purpose: Learn to connect to the database
PHP is simply a function library. The rich functions make some parts of PHP quite simple. It is recommended that you download a PHP function manual so that you can always use it.
I will 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 to the MySQL server. All parameters can be omitted. When this function is used without any parameters, the default value of the hostname parameter is localhost, the default value of the username parameter is the owner of the PHP execution process, and the password parameter is an empty string (that is, there is no password). A colon and port number can be added after the parameter hostname to indicate which port to use to connect to MySQL. Of course, when using a database, using mysql_close() early to close the connection can 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 the database in the MySQL server for subsequent data query operations (query) processing. Returns true on success, false on failure.
The simplest example is:
$conn=mysql_connect ("127.0.0.1", "", "");
mysql_select_db("shop");
Connect to MY SQL Database, open the SHOP database. In practical applications, error judgment should be strengthened.
That’s it for today. Let’s talk about database reading tomorrow.