Explain how to connect and call the database in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:39:04
Original
815 people have browsed it

MySQL is a small and exquisite database server software, which is very ideal for small and medium-sized application systems. In addition to supporting standard ANSI SQL statements, the most important thing is that it also supports multiple platforms. On Unix/Linux systems, MySQL supports multi-threaded operation, which can achieve very good performance. Like PHP and Apache, it is an open source software. Its official website is: http://www.mysql.com, which provides downloads of source code for Windows, Linux, and Unix versions.

Note that MySQL access functions require corresponding permissions to run. Commonly used related functions are introduced as follows:

(1) integer mysql_connect (host, username, password);

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

At the end of script execution, the connection is automatically closed, or it can be closed in advance using mysql_close.

(2) boolean mysql_create_db (database name);

Create a database. Note that the connection must be opened with an account with permission to create databases.

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

Select the default database.

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

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

(5) array mysql_fetch_array (result number);

Take out the next line and return an array. It can be accessed using numeric subscripts (the first field is subscript 0), or it can be accessed using string subscripts (that is, using the respective field names). If the last row has been fetched, return false.

(6) mysql_fetch_row (result number);

Returns a matrix representing all fields in a row in the result set. Each call produces the next row, until false is returned when no rows remain. Each field value is indexed by a zero-based offset. This is the fastest way to get results from a query.

(7) integer mysql_num_rows (result number);

Returns the number of rows in the result set

(8) integer mysql_num_fields (result number);

Returns the number of fields in the result set.

 (9) integer mysql_list_dbs();

Query the server for the database list. It returns a result pointer that can be used with the mysql_fetch_row function and similar functions.

(10) mysql_list_tables (database name);

Get a result pointer pointing to the form list of the specified database. This result pointer can be used by 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. The use of this function is not strictly necessary since all non-permanent links are automatically closed at the end of the script.

(12) mysql_pconnect (host, username, password);

It is completely similar to mysql_connect, but establishes a "permanent connection". Once established, the connection will never be closed, even if the mysql_close function is used or the program is executed. The next time you try to establish a permanent connection, if the system finds that a permanent connection already exists, it will directly return the connection number without re-creating it.

The following is an example of calling a MYSQL database and displaying it in pages.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486442.htmlTechArticleMySQL is a small and exquisite database server software, which is very ideal for small and medium-sized application systems. In addition to supporting standard ANSI SQL statements, the most important thing is that it also supports a variety of...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!