Describes how to use PHP to connect to and call a database

Source: Internet
Author: User
MySQL is a small and flexible database server software that is ideal for medium and small application systems. In addition to supporting standard ANSISQL statements, the most important thing is that it also supports multiple platforms. on Unix/Linux systems, MySQL supports multi-threaded running methods to achieve good performance. Like PHP and Apache, it is an open source generation "> <LINKhref =" http ://

MySQL is a small and flexible database server software that is ideal for medium and small application systems. In addition to standard ansi SQL statements, MySQL also supports multiple platforms. on Unix/Linux systems, MySQL supports multithreading, in this way, we can obtain good performance. Like PHP and Apache, Apache is an open source software. Its official website is: http://www.mysql.com, provided above Windows, Linux, Unix version of the source code download.

Note: MySQL access functions must have the corresponding permissions to run. Common functions are described as follows:

(1) integer mysql_connect (host, user name, password );

This function starts a connection to the MySQL database on the specified host. If the database is on a different port, add the colon and port number after the host name. All parameters are optional. by default, they are corresponding to the local host, the script name being executed by the user, and null. The host can be an IP address or domain name.

When the script execution ends, the connection is automatically closed, or you can use mysql_close to close the connection in advance.

(2) boolean mysql_create_db (database name );

Create a database. Note that you must use an account with the permission to create a database to open the connection.

(3) boolean mysql_select_db (database name, connection number );

Select the default database.

(4) integer mysql_query (SQL statement, connection number );

Queries a specified database. If the SQL statement is select, a result number is returned. Otherwise, the returned value can be ignored. If it fails, false is returned ..

(5) array mysql_fetch_array (result number );

Retrieves the next row and returns an array. It can be accessed by numerical subscript (the first field is subscript 0) or by string subscript (that is, each field name is used ). If the last row is obtained, false is returned ..

(6) mysql_fetch_row (result number );

Returns a matrix representing all fields in a row in the result set. Each call will generate the next row, and false will be returned until there are no remaining rows. Each domain value is indexed by an offset starting from scratch. This is the fastest way to get results from a query.

(7) integer mysql_num_rows (result number );

Number of rows in the returned result set

(8) integer mysql_num_fields (result number );

The number of fields in the returned result set.

(9) integer mysql_list_dbs ();

Query the database list on the server. It returns a result pointer, which can be used in the mysql_fetch_row function and similar functions.

(10) mysql_list_tables (database name );

Returns a result pointer to the list of tables pointing to the specified database. This result pointer can be used for any function that obtains rows from the result set.

(11) mysql_close (connection number );

Close the connection to the database. The connection must be opened by mysql_connect. This function is not strictly required because all non-permanent links are automatically disabled when the script ends.

(12) mysql_pconnect (host, user name, password );

Similar to mysql_connect, but establishing a "permanent connection" never closes a connection after it is established, even if mysql_close function or program execution is completed. If a permanent connection already exists in the system during the next attempt to establish a permanent connection, the connection number is directly returned without re-creation.

The following is an example of calling the MYSQL database and displaying it on pages.

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.