It is not recommended to use this extension when writing new code. You should use MYSQLI or Pdo_mysql extensions instead.
Installation
At compile time, just use the--with-mysql[=dir] configuration option, where optional [DIR] points to the MySQL installation directory.
Although this MySQL extension library is compatible with MySQL 4.1.0 and its later versions, it does not support the additional features offered by these editions. To use these features, 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, execute a query, and then disconnect the MySQL database after printing the result set.
Example #1 MySQL Extension Overview Example
<?php //Connect, select database $link = mysql_connect (' mysql_host ', ' mysql_user ', ' Mysql_password ') or Die (' Could Not connect: '. Mysql_error ()); Echo ' Connected successfully '; mysql_select_db (' my_database ') or Die (' Could not select database '); Execute SQL query $query = ' SELECT * from my_table '; $result = mysql_query ($query) or Die (' Query failed: '. mysql_error ()); Print query results in HTML echo "<table>\n"; while ($line = Mysql_fetch_array ($result, Mysql_assoc)) { echo "\t<tr>\n"; foreach ($line as $col _value) { echo "\t\t<td> $col _value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; Release result set mysql_free_result ($result); Close connection mysql_close ($link);? >
MySQL function
The last optional parameter for most MySQL functions is link_identifier. If this parameter is not provided, the last open connection is used. If the last connection does not exist, it will attempt to connect using the default parameters defined in PHP.ini. If the connection is not successful, the function returns FALSE.
Mysql_affected_rows-gets the number of record rows affected by the previous MySQL operation
mysql_client_encoding-returns the name of the character set
mysql_close-Close MySQL Connection
Mysql_connect-Open a connection to the MySQL server
mysql_create_db-Create a new MySQL database
mysql_data_seek-pointer to move internal result
mysql_db_name-Get Results 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-returns the text error message from the previous MySQL operation
Mysql_escape_string-escapes a string for mysql_query
Mysql_fetch_array-gets a row from the result set as an associative array, or as a numeric array, or both
mysql_fetch_assoc-getting a row from the result set as an associative array
mysql_fetch_field-to get column information from the result set and return as an object
mysql_fetch_lengths-get the length of each output in the result set
mysql_fetch_object-a row from the result set as an object
mysql_fetch_row-a row from the result set as an enumerated array
Mysql_field_flags-the flags associated with the specified field from the result
mysql_field_len-returns the length of the specified field
mysql_field_name-the field name of the specified field in the result
mysql_field_seek-set the pointer in the result set to the specified field offset
Mysql_field_table-gets the name of the table that contains the specified field
Mysql_field_type-gets the type of the specified field in the result set
mysql_free_result-Releasing result memory
Mysql_get_client_info-Getting MySQL Client information
Mysql_get_host_info-Getting MySQL host information
Mysql_get_proto_info-Get MySQL protocol information
mysql_get_server_info-getting MySQL Server information
Mysql_info-get information about a recent query
Mysql_insert_id-gets the ID generated by the insert operation in the previous step
mysql_list_dbs-list all databases in MySQL server
mysql_list_fields-lists the fields in the MySQL results
mysql_list_processes-List MySQL Process
mysql_list_tables-lists the tables in the MySQL database
Mysql_num_fields-get the number of fields in the result set
Mysql_num_rows-get the number of rows in the result set
mysql_pconnect-open a persistent connection to the MySQL server
Mysql_ping-ping A server connection, reconnect if there is no connection
mysql_query-Send a MySQL query
Mysql_real_escape_string-escapes special characters in strings used in SQL statements, and takes into account the current character set of the connection
mysql_result-Get Results data
mysql_select_db-Select MySQL Database
mysql_set_charset-setting the client's character set
mysql_stat-getting the current system state
mysql_tablename-Get Table name
Mysql_thread_id-returns the ID of the current thread
Mysql_unbuffered_query-sends a SQL query to MySQL and does not fetch and cache the resulting rows