10 days Learn PHP Day 4

web front end four thousand five hundred and four 13 years ago (2011-04-08)

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 databases, use MySQL earlier_ Close () can save resources by closing the connection.

    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 ("", "", "");
    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.