MySQL related instructions_PHP tutorial

WBOY
Release: 2016-07-21 15:57:41
Original
840 people have browsed it

Resource Types
There are two resource types used in the MySQL module. The first is the connection handle of the database, and the second is the result set returned by the SQL query.

Predefined constants
The following constants are defined by this extension module, so they are only valid after this extension module is compiled into PHP or is dynamically loaded at runtime.

In PHP 4.3.0 and later versions, more client tags are allowed to be specified in the mysql_connect() function and mysql_pconnect() function. The defined constants are listed below:

Table 2. MySQL client constants

Constant Description
MYSQL_CLIENT_COMPRESS uses compressed communication protocol
MYSQL_CLIENT_IGNORE_SPACE allows spaces after the function name
MYSQL_CLIENT_INTERACTIVE allows setting the interactive_timeout time to wait idle before disconnecting (instead of wait_timeout).
MYSQL_CLIENT_SSL uses SSL encryption. This flag is only available when the MySQL client library version is 4.x or higher. Both PHP 4 and Windows version of PHP 5 installation packages are bundled with 3.23.x. The


mysql_fetch_array() function uses a constant to represent the type of the returned array. The following is the definition of constants:

Table 3. MySQL fetch constants

Constant Description
MYSQL_ASSOC The data column returned uses the field name as the index name of the array.
MYSQL_BOTH The data column returned uses the field name and numeric index as the index name of the array.
MYSQL_NUM The data column returned uses a numeric index as the index name of the array. The index starts at 0 , indicating the first field of the returned result.


Notes
Note: Most MySQL functions accept link_identifier as the last optional parameter. If this parameter is not provided, the last open connection is used. If a connection does not exist, the default parameters defined in php.ini will be used to try to establish a connection. If the connection is unsuccessful, the function returns FALSE.

Example
The following simple example demonstrates how to connect to the database, execute query statements, print the returned result set and disconnect from the database and a series of basic MySQL operations. 例子 1. MySQL 例子

// 连接,选择数据库
$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');

// 执行 SQL 查询
$query = 'Select * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// 用 HTML 显示结果
echo "

n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "tn";
   foreach ($line as $col_value) {
       echo "ttn";
   }
   echo "tn";
}
echo "
$col_value
n";

// Release the result set
mysql_free_result($result);

// Close the connection
mysql_close($link ; User
mysql_client_encoding -- Returns the name of the character set
mysql_close -- Closes the MySQL connection
mysql_connect -- Opens a connection to the MySQL server
mysql_create_db -- Creates a new MySQL database
mysql_data_seek -- Move the internal result pointer
mysql_db_name -- Get the result data
mysql_db_query -- Send a MySQL query
mysql_drop_db -- Drop (delete) a MySQL database
mysql_errno -- Return the previous MySQL operation Numeric encoding of the error message
mysql_error -- Returns the text error message generated by 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 a numeric array, or both
mysql_fetch_assoc -- Get a row from the result set as an associative array
mysql_fetch_field -- Get column information from the result set and return it as an object
mysql_fetch_lengths -- Get each row in the result set The length of the output
mysql_fetch_object -- Get a row from the result set as an object
mysql_fetch_row -- Get a row from the result set as an enumeration array
mysql_field_flags -- Get the flags associated with the specified field from the result
mysql_field_len -- Return the length of the specified field
mysql_field_name -- Get 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 -- Get the specified The name of the table where the field is located
mysql_field_type -- Get the type of the specified field in the result set
mysql_free_result -- Release the result memory
mysql_get_client_info -- Get the MySQL client information
mysql_get_host_info -- Get the MySQL host information
mysql_get_proto_info -- Get MySQL protocol information
mysql_get_server_info -- Get MySQL server information
mysql_info -- Get the latest query information
mysql_insert_id -- Get the ID generated by the previous Insert operation
mysql_list_d bs -- List all databases in the MySQL server
mysql_list_fields -- List the fields in the MySQL results
mysql_list_processes -- List the MySQL processes
mysql_list_tables -- List 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 -- Escape special characters in the string used in the SQL statement, taking into account the current character set of the connection
mysql_result -- Get the result data
mysql_select_db -- Select the MySQL database
mysql_stat -- Get the current system status
mysql_tablename -- Get the table name
mysql_thread_id -- Return the ID of the current thread
mysql_unbuffered_query -- Send a SQL query to MySQL and not Line to get and cache results




http://www.bkjia.com/PHPjc/317799.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/317799.htmlTechArticleResource Types There are two resource types used in the MySQL module. The first is the connection handle of the database, and the second is the result set returned by the SQL query. Predefined constants The following constants are modeled by this extension...
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