Learning purpose: learn to connect data base
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, which is always useful.
Let me briefly talk about connecting to the MYSQL database.
1、 mysql_connect
Open MySQL The server connect.
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 this function is used without any parameters, the default value of the parameter hostname is localhost, the default value of the parameter username is the owner of the PHP execution journey, and the parameter password is an empty string (that is, there is no password). The parameter hostname can be followed by a colon and port number to indicate which port is used to connect to MySQL. Of course, when using the database, use mysql_close() earlier to close the connection 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 the database in the MySQL server for subsequent data query processing. Returns true on success and false on failure.
The simplest example is:
$conn=mysql_connect ("127.0.0.1", "", "");
mysql_select_db("shop");
Connect the MY SQL database and open the SHOP database. In practical application, the point error judgment should be strengthened.
That's all for today. Let's talk about reading the database tomorrow.