Three API_MySQL-mysql tutorials for connecting php to mysql database

Source: Internet
Author: User
Tags mysql functions mysql host
For the three APIs used by php to connect to the mysql database, refer to the self-php Manual. This article does not make much sense. it is just for your convenience to access the Internet.

1. MySQL extension of PHP
2. mysqli extension of PHP
3. PHP Data object (PDO)

MySQL extension functions
This is an early extension of design and development that allows PHP applications to interact with MySQL databases.MysqlExtension provides a process-oriented interface and is designed for MySQL 4.1.3 or earlier versions. Therefore, although this extension can interact with MySQL4.1.3 or the updated database server, it does not support some features provided by the MySQL server later.

  • 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-Sets the client character set
  • 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.

Mysqli extension of PHP
MysqliExtensions, which are sometimes called MySQL enhanced extensions, can be used to use advanced features in MySQL 4.1.3 or later versions.MysqliExtensions are included in PHP 5 and later versions.

Object-oriented interface
Supported prepared statements
Multi-statement execution support
Transaction Support
Enhanced debugging capability
Embedded Service Support
If you use MySQL4.1.3 or the latest version, we strongly recommend that you use this extension.
MySQLi{

/* Attribute */

Int $ MySQLi-> affected_rows;

String $ client_info;

Int $ client_version;

String $ connect_errno;

String $ connect_error;

Int $ errno;

String $ error;

Int $ field_count;

Int $ client_version;

String $ host_info;

String $ protocol_version;

String $ server_info;

Int $ server_version;

String $ info;

Mixed $ insert_id;

String $ sqlstate;

Int $ thread_id;

Int $ warning_count;

/* Method */

Int mysqli_affected_rows (mysqli $ link)

Bool mysqli: autocommit (bool $ mode)

Bool mysqli: change_user (string $ user, string $ password, string $ database)

String mysqli: character_set_name (void)

String mysqli_get_client_info (mysqli $ link)

Int mysqli_get_client_version (mysqli $ link)

Bool mysqli: close (void)

Bool mysqli: commit (void)

Int mysqli_connect_errno (void)

String mysqli_connect_error (void)

Mysqli mysqli_connect ([string $ host = ini_get ("mysqli. default_host ") [, string $ username = ini_get (" mysqli. default_user ") [, string $ passwd = ini_get (" mysqli. default_pw ") [, string $ dbname =" "[, int $ port = ini_get (" mysqli. default_port ") [, string $ socket = ini_get (" mysqli. default_socket ")])

Bool mysqli: debug (string $ message)

Bool mysqli: dump_debug_info (void)

Int mysqli_errno (mysqli $ link)

String mysqli_error (mysqli $ link)

Int mysqli_field_count (mysqli $ link)

Object mysqli: get_charset (void)

String mysqli: get_client_info (void)

Array mysqli_get_client_stats (void)

Int mysqli_get_client_version (mysqli $ link)

Bool mysqli: get_connection_stats (void)

String mysqli_get_host_info (mysqli $ link)

Int mysqli_get_proto_info (mysqli $ link)

String mysqli_get_server_info (mysqli $ link)

Int mysqli_get_server_version (mysqli $ link)

Mysqli_warning mysqli: get_warnings (void)

String mysqli_info (mysqli $ link)

Mysqli: init (void)

Mixed mysqli_insert_id (mysqli $ link)

Bool mysqli: kill (int $ processid)

Bool mysqli: more_results (void)

Bool mysqli: multi_query (string $ query)

Bool mysqli: next_result (void)

Bool mysqli: options (int $ option, mixed $ value)

Bool mysqli: ping (void)

Public int mysqli: poll (array & $ read, array & $ error, array & $ reject, int $ sec [, int $ usec])

Mysqli_stmt mysqli: prepare (string $ query)

Mixed mysqli: query (string $ query [, int $ resultmode])

Bool mysqli: real_connect ([string $ host [, string $ username [, string $ passwd [, string $ dbname [, int $ port [, string $ socket [, int $ flags])

String mysqli: escape_string (string $ escapestr)

Bool mysqli: real_query (string $ query)

Public mysqli_result mysqli: reap_async_query (void)

Bool mysqli: rollback (void)

Bool mysqli: select_db (string $ dbname)

Bool mysqli: set_charset (string $ charset)

Void mysqli_set_local_infile_default (mysqli $ link)

Bool mysqli: set_local_infile_handler (mysqli $ link, callback $ read_func)

String mysqli_sqlstate (mysqli $ link)

Bool mysqli: ssl_set (string $ key, string $ cert, string $ ca, string $ capath, string $ cipher)

String mysqli: stat (void)

Mysqli_stmt mysqli: stmt_init (void)

Mysqli_result mysqli: store_result (void)

Int mysqli_thread_id (mysqli $ link)

Bool mysqli_thread_safe (void)

Mysqli_result mysqli: use_result (void)

Int mysqli_warning_count (mysqli $ link)

}

Table of Contents

  • Mysqli-> affected_rows-Gets the number of affected rows in a previous MySQL operation
  • Mysqli: autocommit-Turns on or off auto-commiting database modifications
  • Mysqli: change_user-Changes the user of the specified database connection
  • Mysqli: character_set_name-Returns the default character set for the database connection
  • Mysqli-> client_info-Returns the MySQL client version as a string
  • Mysqli-> client_version-Get MySQL client info
  • Mysqli: close-Closes a previusly opened database connection
  • Mysqli: commit-Commits the current transaction
  • Mysqli-> connect_errno-Returns the error code from last connect call
  • Mysqli-> connect_error-Returns a string description of the last connect error
  • Mysqli ::__ construct-Open a new connection to the MySQL server
  • Mysqli: debug-Performs debugging operations
  • Mysqli: dump_debug_info-Dump debugging information into the log
  • Mysqli-> errno-Returns the error code for the most recent function call
  • Mysqli-> error-Returns a string description of the last error
  • Mysqli-> field_count-Returns the number of columns for the most recent query
  • Mysqli: get_charset-Returns a character set object
  • Mysqli-> get_client_info-Returns the MySQL client version as a string
  • Mysqli_get_client_stats-Returns client per-process statistics
  • Mysqli-> client_version-Get MySQL client info
  • Mysqli: get_connection_stats-Returns statistics about the client connection
  • Mysqli-> host_info-Returns a string representing the type of connection used
  • Mysqli-> protocol_version-Returns the version of the MySQL protocol used
  • Mysqli-> server_info-Returns the version of the MySQL server
  • Mysqli-> server_version-Returns the version of the MySQL server as an integer
  • Mysqli: get_warnings-Get result of SHOW WARNINGS
  • Mysqli-> info-Retrieves information about the most recently executed query
  • Mysqli: init-Initializes MySQLi and returns a resource for use with mysqli_real_connect ()
  • Mysqli-> insert_id-Returns the auto generated id used in the last query
  • Mysqli: kill-Asks the server to kill a MySQL thread
  • Mysqli: more_results-Check if there are any more query results from a multi query
  • Mysqli: multi_query-Performs a query on the database
  • Mysqli: next_result-Prepare next result from multi_query
  • Mysqli: options-Set options
  • Mysqli: ping-Pings a server connection, or tries to reconnect if the connection has gone down
  • Mysqli: poll-Poll connections
  • Mysqli: prepare-Prepare an SQL statement for execution
  • Mysqli: query-Performs a query on the database
  • Mysqli: real_connect-Opens a connection to a mysql server
  • Mysqli: real_escape_string-Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection
  • Mysqli: real_query-Execute an SQL query
  • Mysqli: reap_async_query-Get result from async query
  • Mysqli: rollback-Rolls back current transaction
  • Mysqli: select_db-Selects the default database for database queries
  • Mysqli: set_charset-Sets the default client character set
  • Mysqli: set_local_infile_default-Unsets user defined handler for load local infile command
  • Mysqli: set_local_infile_handler-Set callback function for load data local infile command
  • Mysqli-> sqlstate-Returns the SQLSTATE error from previous MySQL operation
  • Mysqli: ssl_set-Used for establishing secure connections using SSL
  • Mysqli: stat-Gets the current system status
  • Mysqli: stmt_init-Initializes a statement and returns an object for use with mysqli_stmt_prepare
  • Mysqli: store_result-Transfers a result set from the last query
  • Mysqli-> thread_id-Returns the thread ID for the current connection
  • Mysqli: thread_safe-Returns whether thread safety is given or not
  • Mysqli: use_result-Initiate a result set retrieval
  • Mysqli-> warning_count-Returns the number of warnings from the last query for the given link



PHP Data object (PDO)
PHP Data objects are a database abstraction layer specification in PHP applications. PDO provides a unified API so that your PHP application does not care about the type of the database server to be connected. That is to say, if you use the pdo api, you can seamlessly switch the database server as needed, for example, from Firebird to MySQL, you only need to modify a few PHP code.
Of course, PDO also has its own advantages, such as a clean, simple, and portable API, its primary drawback is that it will limit your inability to use all the advanced database features provided by the MySQL server later. For example, PDO does not allow MySQL-supported multi-statement execution.
The MySQL driver of PDO is not a set of APIs, at least from the perspective of PHP programmers. In fact, the MySQL driver of PDO is in its own lower layer and provides specific Mysql functions. Programmers directly call the pdo api, while PDO uses the PDO MySQL driver to complete interaction with the MySQL server.
The MySQL driver of PDO is one of the many PDO drivers. Other available PDO drivers include Firebird and PostgreSQL.

PDO{

_ Construct (string $ dsn [, string $ username [, string $ password [, array $ driver_options])

Bool beginTransaction (void)

Bool commit (void)

Mixed errorCode (void)

Array errorInfo (void)

Int exec (string $ statement)

Mixed getAttribute (int $ attribute)

Array getAvailableDrivers (void)

Bool inTransaction (void)

String lastInsertId ([string $ name = NULL])

PDOStatement prepare (string $ statement [, array $ driver_options = array ()])

PDOStatement query (string $ statement)

String quote (string $ string [, int $ parameter_type = PDO: PARAM_STR])

Bool rollBack (void)

Bool setAttribute (int $ attribute, mixed $ value)

}


Table of Contents

  • PDO: beginTransaction-Initiates a transaction
  • PDO: commit-Commits a transaction
  • PDO: :__ construct-Creates a PDO instance representing a connection to a database
  • PDO: errorCode-Fetch the SQLSTATE associated with the last operation on the database handle
  • PDO: errorInfo-Fetch extended error information associated with the last operation on the database handle
  • PDO: exec-Execute an SQL statement and return the number of affected rows
  • PDO: getAttribute-Retrieve a database connection attribute
  • PDO: getAvailableDrivers-Return an array of available PDO drivers
  • PDO: inTransaction-Checks if inside a transaction
  • PDO: lastInsertId-Returns the ID of the last inserted row or sequence value
  • PDO: prepare-Prepares a statement for execution and returns a statement object
  • PDO: query-Executes an SQL statement, returning a result set as a PDOStatement object
  • PDO: quote-Quotes a string for use in a query.
  • PDO: rollBack-Rolls back a transaction
  • PDO: setAttribute-Set an attribute

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.