10 days to learn the fourth day of PHP _php

Source: Internet
Author: User
Keywords learn connect database function parameters use MySQL return S
Learning Purpose: Learn to connect to a database

PHP is simply a library of functions, rich in functions that make some parts of Php quite simple. We recommend that you down a PHP function manual, the total use of the.

I'll just talk about it here. Connect to MySQL database.

1, Mysql_connect

Open the MySQL server connection.
Syntax: int mysql_connect (string [hostname] [:p ort], string [username], string [password]); return value: Integer

This function establishes a connection to the MySQL server. All of these parameters can be omitted. When using this function without any arguments, the default value of the parameter hostname is localhost, the default value for the parameter username is the owner of the PHP execution itinerary, and the parameter password is an empty string (that is, no password). The parameter hostname can be followed by a colon and a port number, which represents which port to use for MySQL connection. Of course, when using the database, using Mysql_close () to turn off the connection earlier 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 jobs (query) processing. The success returns True, and False if it fails.

The simplest examples are:
$conn =mysql_connect ("127.0.0.1", "", "" ");
mysql_select_db ("Shop");
Connect your computer to my SQL database and open the shop database. In practical application, the point error judgment should be strengthened.

We'll talk about it today. Read the database again tomorrow.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.