Home > Backend Development > PHP Tutorial > The fourth day of learning PHP in ten days_PHP tutorial

The fourth day of learning PHP in ten days_PHP tutorial

WBOY
Release: 2016-07-21 16:08:04
Original
861 people have browsed it

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314903.htmlTechArticleLearning 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template