The native MySQLAPI of PHP database extension does not recommend this extension when writing new code. You should use mysqli or PDO_MySQL extension instead.
Install
During compilation, you only need to use the -- with-mysql [= DIR] configuration option. the optional [DIR] points to the MySQL installation directory.
Although this MySQL extension Library is compatible with MySQL 4.1.0 and later versions, it does not support additional features provided by these versions. To use these functions, use the MySQLi Extension Library.
If you want to install both the mysql extension Library and the mysqli Extension Library, you must use the same client library to avoid any conflicts.
Example
This simple example shows how to connect and execute a query. print the result set and disconnect the MySQL database.
Example #1 Examples of MySQL extension
\ N "; while ($ line = mysql_fetch_array ($ result, MYSQL_ASSOC) {echo" \ t\ N "; foreach ($ line as $ col_value) {echo" \ t$ Col_value\ N ";} echo" \ t\ N ";} echo"\ N "; // release the result set mysql_free_result ($ result); // close the connection mysql_close ($ link);?>
MySQL functions
The last optional parameter of most MySQL functions is link_identifier. If this parameter is not provided, the last opened connection is used. If the last opened connection does not exist, the connection will be connected using the default parameter defined in php. ini. If the connection fails, the function returns FALSE.
Mysql_affected_rows-obtain the number of records affected by the previous MySQL operation
Mysql_client_encoding-name of the returned character set
Mysql_close-close MySQL connection
Mysql_connect-open a connection to the MySQL server
Mysql_create_db-create a MySQL database
Mysql_data_seek-move internal result Pointer
Mysql_db_name-get result data
Mysql_db_query-send a MySQL Query
Mysql_drop_db-discard (delete) a MySQL database
Mysql_errno-returns the numeric encoding of the error message in the previous MySQL operation
Mysql_error-return the text error message generated by the previous MySQL operation
Mysql_escape_string-escape a string for mysql_query
Mysql_fetch_array-get a row from the result set as an associated array, or number array, or both
Mysql_fetch_assoc-get a row from the result set as the associated array
Mysql_fetch_field-retrieve column information from the result set and return it as an object
Mysql_fetch_lengths-length of each output in the result set
Mysql_fetch_object-get a row from the result set as an object
Mysql_fetch_row-retrieve a row from the result set as an enumerated array
Mysql_field_flags-retrieve the flag associated with the specified field from the result
Mysql_field_len-return the length of the specified field
Mysql_field_name-field name of the specified field in the result obtained
Mysql_field_seek-set the pointer in the result set to the specified field offset.
Mysql_field_table-get the name of the table where the specified field is located
Mysql_field_type-specify the field type in the result set.
Mysql_free_result-release result memory
Mysql_get_client_info-obtain MySQL client information
Mysql_get_host_info-obtain MySQL host information
Mysql_get_proto_info-obtain MySQL protocol information
Mysql_get_server_info-obtain MySQL server information
Mysql_info-obtain the information of the last query
Mysql_insert_id-get the ID generated by the previous INSERT operation
Mysql_list_dbs-list all databases on the MySQL server
Mysql_list_fields-list fields in MySQL results
Mysql_list_processes-list MySQL processes
Mysql_list_tables-list tables in the MySQL database
Mysql_num_fields-number of fields in the result set obtained
Mysql_num_rows-number of rows in the result set
Mysql_pconnect-open a persistent connection to the MySQL server
Mysql_ping-Ping a server connection. if there is no connection, reconnect.
Mysql_query-send a MySQL Query
Mysql_real_escape_string-special characters in the character strings used in the escape SQL statement, taking into account the connected current character set
Mysql_result-get result data
Mysql_select_db-select MySQL database
Mysql_set_charset-set the character set of the client
Mysql_stat-get the current system status
Mysql_tablename-get the table name
Mysql_thread_id-returns the ID of the current thread
Mysql_unbuffered_query-a row that sends an SQL query to MySQL and does not obtain or cache the result.