MySQL PHP API

Abstract

This manual describes the PHP extensions and interfaces that can be used with MySQL.

Document generated on: 2014-07-14 (revision: 39312)


Table of Contents

Preface and Legal Notices
1 Introduction to the MySQL PHP API
2 Overview of the MySQL PHP drivers
2.1 Introduction
2.2 Terminology overview
2.3 Choosing an API
2.4 Choosing a library
2.5 Concepts
2.5.1 Buffered and Unbuffered queries
2.5.2 Character sets
3 MySQL Improved Extension (Mysqli)
3.1 Examples
3.2 Overview
3.3 Quick start guide
3.3.1 Dual procedural and object-oriented interface
3.3.2 Connections
3.3.3 Executing statements
3.3.4 Prepared Statements
3.3.5 Stored Procedures
3.3.6 Multiple Statements
3.3.7 API support for transactions
3.3.8 Metadata
3.4 Installing/Configuring
3.4.1 Requirements
3.4.2 Installation
3.4.3 Runtime Configuration
3.4.4 Resource Types
3.5 The mysqli Extension and Persistent Connections
3.6 Predefined Constants
3.7 Notes
3.8 The MySQLi Extension Function Summary
3.9 The mysqli class (mysqli)
3.9.1 mysqli::$affected_rows, mysqli_affected_rows
3.9.2 mysqli::autocommit, mysqli_autocommit
3.9.3 mysqli::begin_transaction, mysqli_begin_transaction
3.9.4 mysqli::change_user, mysqli_change_user
3.9.5 mysqli::character_set_name, mysqli_character_set_name
3.9.6 mysqli::$client_info, mysqli_get_client_info
3.9.7 mysqli::$client_version, mysqli_get_client_version
3.9.8 mysqli::close, mysqli_close
3.9.9 mysqli::commit, mysqli_commit
3.9.10 mysqli::$connect_errno, mysqli_connect_errno
3.9.11 mysqli::$connect_error, mysqli_connect_error
3.9.12 mysqli::__construct, mysqli_connect
3.9.13 mysqli::debug, mysqli_debug
3.9.14 mysqli::dump_debug_info, mysqli_dump_debug_info
3.9.15 mysqli::$errno, mysqli_errno
3.9.16 mysqli::$error_list, mysqli_error_list
3.9.17 mysqli::$error, mysqli_error
3.9.18 mysqli::$field_count, mysqli_field_count
3.9.19 mysqli::get_charset, mysqli_get_charset
3.9.20 mysqli::get_client_info, mysqli_get_client_info
3.9.21 mysqli_get_client_stats
3.9.22 mysqli_get_client_version, mysqli::$client_version
3.9.23 mysqli::get_connection_stats, mysqli_get_connection_stats
3.9.24 mysqli::$host_info, mysqli_get_host_info
3.9.25 mysqli::$protocol_version, mysqli_get_proto_info
3.9.26 mysqli::$server_info, mysqli_get_server_info
3.9.27 mysqli::$server_version, mysqli_get_server_version
3.9.28 mysqli::get_warnings, mysqli_get_warnings
3.9.29 mysqli::$info, mysqli_info
3.9.30 mysqli::init, mysqli_init
3.9.31 mysqli::$insert_id, mysqli_insert_id
3.9.32 mysqli::kill, mysqli_kill
3.9.33 mysqli::more_results, mysqli_more_results
3.9.34 mysqli::multi_query, mysqli_multi_query
3.9.35 mysqli::next_result, mysqli_next_result
3.9.36 mysqli::options, mysqli_options
3.9.37 mysqli::ping, mysqli_ping
3.9.38 mysqli::poll, mysqli_poll
3.9.39 mysqli::prepare, mysqli_prepare
3.9.40 mysqli::query, mysqli_query
3.9.41 mysqli::real_connect, mysqli_real_connect
3.9.42 mysqli::real_escape_string, mysqli_real_escape_string
3.9.43 mysqli::real_query, mysqli_real_query
3.9.44 mysqli::reap_async_query, mysqli_reap_async_query
3.9.45 mysqli::refresh, mysqli_refresh
3.9.46 mysqli::release_savepoint, mysqli_release_savepoint
3.9.47 mysqli::rollback, mysqli_rollback
3.9.48 mysqli::rpl_query_type, mysqli_rpl_query_type
3.9.49 mysqli::savepoint, mysqli_savepoint
3.9.50 mysqli::select_db, mysqli_select_db
3.9.51 mysqli::send_query, mysqli_send_query
3.9.52 mysqli::set_charset, mysqli_set_charset
3.9.53 mysqli::set_local_infile_default, mysqli_set_local_infile_default
3.9.54 mysqli::set_local_infile_handler, mysqli_set_local_infile_handler
3.9.55 mysqli::$sqlstate, mysqli_sqlstate
3.9.56 mysqli::ssl_set, mysqli_ssl_set
3.9.57 mysqli::stat, mysqli_stat
3.9.58 mysqli::stmt_init, mysqli_stmt_init
3.9.59 mysqli::store_result, mysqli_store_result
3.9.60 mysqli::$thread_id, mysqli_thread_id
3.9.61 mysqli::thread_safe, mysqli_thread_safe
3.9.62 mysqli::use_result, mysqli_use_result
3.9.63 mysqli::$warning_count, mysqli_warning_count
3.10 The mysqli_stmt class (mysqli_stmt)
3.10.1 mysqli_stmt::$affected_rows, mysqli_stmt_affected_rows
3.10.2 mysqli_stmt::attr_get, mysqli_stmt_attr_get
3.10.3 mysqli_stmt::attr_set, mysqli_stmt_attr_set
3.10.4 mysqli_stmt::bind_param, mysqli_stmt_bind_param
3.10.5 mysqli_stmt::bind_result, mysqli_stmt_bind_result
3.10.6 mysqli_stmt::close, mysqli_stmt_close
3.10.7 mysqli_stmt::data_seek, mysqli_stmt_data_seek
3.10.8 mysqli_stmt::$errno, mysqli_stmt_errno
3.10.9 mysqli_stmt::$error_list, mysqli_stmt_error_list
3.10.10 mysqli_stmt::$error, mysqli_stmt_error
3.10.11 mysqli_stmt::execute, mysqli_stmt_execute
3.10.12 mysqli_stmt::fetch, mysqli_stmt_fetch
3.10.13 mysqli_stmt::$field_count, mysqli_stmt_field_count
3.10.14 mysqli_stmt::free_result, mysqli_stmt_free_result
3.10.15 mysqli_stmt::get_result, mysqli_stmt_get_result
3.10.16 mysqli_stmt::get_warnings, mysqli_stmt_get_warnings
3.10.17 mysqli_stmt::$insert_id, mysqli_stmt_insert_id
3.10.18 mysqli_stmt::more_results, mysqli_stmt_more_results
3.10.19 mysqli_stmt::next_result, mysqli_stmt_next_result
3.10.20 mysqli_stmt::$num_rows, mysqli_stmt_num_rows
3.10.21 mysqli_stmt::$param_count, mysqli_stmt_param_count
3.10.22 mysqli_stmt::prepare, mysqli_stmt_prepare
3.10.23 mysqli_stmt::reset, mysqli_stmt_reset
3.10.24 mysqli_stmt::result_metadata, mysqli_stmt_result_metadata
3.10.25 mysqli_stmt::send_long_data, mysqli_stmt_send_long_data
3.10.26 mysqli_stmt::$sqlstate, mysqli_stmt_sqlstate
3.10.27 mysqli_stmt::store_result, mysqli_stmt_store_result
3.11 The mysqli_result class (mysqli_result)
3.11.1 mysqli_result::$current_field, mysqli_field_tell
3.11.2 mysqli_result::data_seek, mysqli_data_seek
3.11.3 mysqli_result::fetch_all, mysqli_fetch_all
3.11.4 mysqli_result::fetch_array, mysqli_fetch_array
3.11.5 mysqli_result::fetch_assoc, mysqli_fetch_assoc
3.11.6 mysqli_result::fetch_field_direct, mysqli_fetch_field_direct
3.11.7 mysqli_result::fetch_field, mysqli_fetch_field
3.11.8 mysqli_result::fetch_fields, mysqli_fetch_fields
3.11.9 mysqli_result::fetch_object, mysqli_fetch_object
3.11.10 mysqli_result::fetch_row, mysqli_fetch_row
3.11.11 mysqli_result::$field_count, mysqli_num_fields
3.11.12 mysqli_result::field_seek, mysqli_field_seek
3.11.13 mysqli_result::free, mysqli_free_result
3.11.14 mysqli_result::$lengths, mysqli_fetch_lengths
3.11.15 mysqli_result::$num_rows, mysqli_num_rows
3.12 The mysqli_driver class (mysqli_driver)
3.12.1 mysqli_driver::embedded_server_end, mysqli_embedded_server_end
3.12.2 mysqli_driver::embedded_server_start, mysqli_embedded_server_start
3.12.3 mysqli_driver::$report_mode, mysqli_report
3.13 The mysqli_warning class (mysqli_warning)
3.13.1 mysqli_warning::__construct
3.13.2 mysqli_warning::next
3.14 The mysqli_sql_exception class (mysqli_sql_exception)
3.15 Aliases and deprecated Mysqli Functions
3.15.1 mysqli_bind_param
3.15.2 mysqli_bind_result
3.15.3 mysqli_client_encoding
3.15.4 mysqli_connect
3.15.5 mysqli::disable_reads_from_master, mysqli_disable_reads_from_master
3.15.6 mysqli_disable_rpl_parse
3.15.7 mysqli_enable_reads_from_master
3.15.8 mysqli_enable_rpl_parse
3.15.9 mysqli_escape_string
3.15.10 mysqli_execute
3.15.11 mysqli_fetch
3.15.12 mysqli_get_cache_stats
3.15.13 mysqli_get_metadata
3.15.14 mysqli_master_query
3.15.15 mysqli_param_count
3.15.16 mysqli_report
3.15.17 mysqli_rpl_parse_enabled
3.15.18 mysqli_rpl_probe
3.15.19 mysqli_send_long_data
3.15.20 mysqli::set_opt, mysqli_set_opt
3.15.21 mysqli_slave_query
3.16 Changelog
4 MySQL Functions (PDO_MYSQL) (MySQL (PDO))
4.1 PDO_MYSQL DSN
5 Original MySQL API (Mysql)
5.1 Installing/Configuring
5.1.1 Requirements
5.1.2 Installation
5.1.3 Runtime Configuration
5.1.4 Resource Types
5.2 Changelog
5.3 Predefined Constants
5.4 Examples
5.4.1 MySQL extension overview example
5.5 MySQL Functions
5.5.1 mysql_affected_rows
5.5.2 mysql_client_encoding
5.5.3 mysql_close
5.5.4 mysql_connect
5.5.5 mysql_create_db
5.5.6 mysql_data_seek
5.5.7 mysql_db_name
5.5.8 mysql_db_query
5.5.9 mysql_drop_db
5.5.10 mysql_errno
5.5.11 mysql_error
5.5.12 mysql_escape_string
5.5.13 mysql_fetch_array
5.5.14 mysql_fetch_assoc
5.5.15 mysql_fetch_field
5.5.16 mysql_fetch_lengths
5.5.17 mysql_fetch_object
5.5.18 mysql_fetch_row
5.5.19 mysql_field_flags
5.5.20 mysql_field_len
5.5.21 mysql_field_name
5.5.22 mysql_field_seek
5.5.23 mysql_field_table
5.5.24 mysql_field_type
5.5.25 mysql_free_result
5.5.26 mysql_get_client_info
5.5.27 mysql_get_host_info
5.5.28 mysql_get_proto_info
5.5.29 mysql_get_server_info
5.5.30 mysql_info
5.5.31 mysql_insert_id
5.5.32 mysql_list_dbs
5.5.33 mysql_list_fields
5.5.34 mysql_list_processes
5.5.35 mysql_list_tables
5.5.36 mysql_num_fields
5.5.37 mysql_num_rows
5.5.38 mysql_pconnect
5.5.39 mysql_ping
5.5.40 mysql_query
5.5.41 mysql_real_escape_string
5.5.42 mysql_result
5.5.43 mysql_select_db
5.5.44 mysql_set_charset
5.5.45 mysql_stat
5.5.46 mysql_tablename
5.5.47 mysql_thread_id
5.5.48 mysql_unbuffered_query
6 MySQL Native Driver (Mysqlnd)
6.1 Overview
6.2 Installation
6.3 Runtime Configuration
6.4 Incompatibilities
6.5 Persistent Connections
6.6 Statistics
6.7 Notes
6.8 Memory management
6.9 MySQL Native Driver Plugin API
6.9.1 A comparison of mysqlnd plugins with MySQL Proxy
6.9.2 Obtaining the mysqlnd plugin API
6.9.3 MySQL Native Driver Plugin Architecture
6.9.4 The mysqlnd plugin API
6.9.5 Getting started building a mysqlnd plugin
7 Mysqlnd replication and load balancing plugin (mysqlnd_ms)
7.1 Key Features
7.2 Limitations
7.3 On the name
7.4 Quickstart and Examples
7.4.1 Setup
7.4.2 Running statements
7.4.3 Connection state
7.4.4 SQL Hints
7.4.5 Local transactions
7.4.6 XA/Distributed Transactions
7.4.7 Service level and consistency
7.4.8 Global transaction IDs
7.4.9 Cache integration
7.4.10 Failover
7.4.11 Partitioning and Sharding
7.4.12 MySQL Fabric
7.5 Concepts
7.5.1 Architecture
7.5.2 Connection pooling and switching
7.5.3 Transaction handling
7.5.4 Error handling
7.5.5 Transient errors
7.5.6 Failover
7.5.7 Load balancing
7.5.8 Read-write splitting
7.5.9 Filter
7.5.10 Service level and consistency
7.5.11 Global transaction IDs
7.5.12 Cache integration
7.5.13 Supported clusters
7.6 Installing/Configuring
7.6.1 Requirements
7.6.2 Installation
7.6.3 Runtime Configuration
7.6.4 Plugin configuration file (>=1.1.x)
7.7 Predefined Constants
7.8 Mysqlnd_ms Functions
7.8.1 mysqlnd_ms_dump_servers
7.8.2 mysqlnd_ms_fabric_select_global
7.8.3 mysqlnd_ms_fabric_select_shard
7.8.4 mysqlnd_ms_get_last_gtid
7.8.5 mysqlnd_ms_get_last_used_connection
7.8.6 mysqlnd_ms_get_stats
7.8.7 mysqlnd_ms_match_wild
7.8.8 mysqlnd_ms_query_is_select
7.8.9 mysqlnd_ms_set_qos
7.8.10 mysqlnd_ms_set_user_pick_server
7.8.11 mysqlnd_ms_xa_begin
7.8.12 mysqlnd_ms_xa_commit
7.8.13 mysqlnd_ms_xa_gc
7.8.14 mysqlnd_ms_xa_rollback
7.9 Change History
7.9.1 PECL/mysqlnd_ms 1.6 series
7.9.2 PECL/mysqlnd_ms 1.5 series
7.9.3 PECL/mysqlnd_ms 1.4 series
7.9.4 PECL/mysqlnd_ms 1.3 series
7.9.5 PECL/mysqlnd_ms 1.2 series
7.9.6 PECL/mysqlnd_ms 1.1 series
7.9.7 PECL/mysqlnd_ms 1.0 series
8 Mysqlnd query result cache plugin (mysqlnd_qc)
8.1 Key Features
8.2 Limitations
8.3 On the name
8.4 Quickstart and Examples
8.4.1 Architecture and Concepts
8.4.2 Setup
8.4.3 Caching queries
8.4.4 Setting the TTL
8.4.5 Pattern based caching
8.4.6 Slam defense
8.4.7 Finding cache candidates
8.4.8 Measuring cache efficiency
8.4.9 Beyond TTL: user-defined storage
8.5 Installing/Configuring
8.5.1 Requirements
8.5.2 Installation
8.5.3 Runtime Configuration
8.6 Predefined Constants
8.7 mysqlnd_qc Functions
8.7.1 mysqlnd_qc_clear_cache
8.7.2 mysqlnd_qc_get_available_handlers
8.7.3 mysqlnd_qc_get_cache_info
8.7.4 mysqlnd_qc_get_core_stats
8.7.5 mysqlnd_qc_get_normalized_query_trace_log
8.7.6 mysqlnd_qc_get_query_trace_log
8.7.7 mysqlnd_qc_set_cache_condition
8.7.8 mysqlnd_qc_set_is_select
8.7.9 mysqlnd_qc_set_storage_handler
8.7.10 mysqlnd_qc_set_user_handlers
8.8 Change History
8.8.1 PECL/mysqlnd_qc 1.2 series
8.8.2 PECL/mysqlnd_qc 1.1 series
8.8.3 PECL/mysqlnd_qc 1.0 series
9 Mysqlnd user handler plugin (mysqlnd_uh)
9.1 Security considerations
9.2 Documentation note
9.3 On the name
9.4 Quickstart and Examples
9.4.1 Setup
9.4.2 How it works
9.4.3 Installing a proxy
9.4.4 Basic query monitoring
9.5 Installing/Configuring
9.5.1 Requirements
9.5.2 Installation
9.5.3 Runtime Configuration
9.5.4 Resource Types
9.6 Predefined Constants
9.7 The MysqlndUhConnection class (MysqlndUhConnection)
9.7.1 MysqlndUhConnection::changeUser
9.7.2 MysqlndUhConnection::charsetName
9.7.3 MysqlndUhConnection::close
9.7.4 MysqlndUhConnection::connect
9.7.5 MysqlndUhConnection::__construct
9.7.6 MysqlndUhConnection::endPSession
9.7.7 MysqlndUhConnection::escapeString
9.7.8 MysqlndUhConnection::getAffectedRows
9.7.9 MysqlndUhConnection::getErrorNumber
9.7.10 MysqlndUhConnection::getErrorString
9.7.11 MysqlndUhConnection::getFieldCount
9.7.12 MysqlndUhConnection::getHostInformation
9.7.13 MysqlndUhConnection::getLastInsertId
9.7.14 MysqlndUhConnection::getLastMessage
9.7.15 MysqlndUhConnection::getProtocolInformation
9.7.16 MysqlndUhConnection::getServerInformation
9.7.17 MysqlndUhConnection::getServerStatistics
9.7.18 MysqlndUhConnection::getServerVersion
9.7.19 MysqlndUhConnection::getSqlstate
9.7.20 MysqlndUhConnection::getStatistics
9.7.21 MysqlndUhConnection::getThreadId
9.7.22 MysqlndUhConnection::getWarningCount
9.7.23 MysqlndUhConnection::init
9.7.24 MysqlndUhConnection::killConnection
9.7.25 MysqlndUhConnection::listFields
9.7.26 MysqlndUhConnection::listMethod
9.7.27 MysqlndUhConnection::moreResults
9.7.28 MysqlndUhConnection::nextResult
9.7.29 MysqlndUhConnection::ping
9.7.30 MysqlndUhConnection::query
9.7.31 MysqlndUhConnection::queryReadResultsetHeader
9.7.32 MysqlndUhConnection::reapQuery
9.7.33 MysqlndUhConnection::refreshServer
9.7.34 MysqlndUhConnection::restartPSession
9.7.35 MysqlndUhConnection::selectDb
9.7.36 MysqlndUhConnection::sendClose
9.7.37 MysqlndUhConnection::sendQuery
9.7.38 MysqlndUhConnection::serverDumpDebugInformation
9.7.39 MysqlndUhConnection::setAutocommit
9.7.40 MysqlndUhConnection::setCharset
9.7.41 MysqlndUhConnection::setClientOption
9.7.42 MysqlndUhConnection::setServerOption
9.7.43 MysqlndUhConnection::shutdownServer
9.7.44 MysqlndUhConnection::simpleCommand
9.7.45 MysqlndUhConnection::simpleCommandHandleResponse
9.7.46 MysqlndUhConnection::sslSet
9.7.47 MysqlndUhConnection::stmtInit
9.7.48 MysqlndUhConnection::storeResult
9.7.49 MysqlndUhConnection::txCommit
9.7.50 MysqlndUhConnection::txRollback
9.7.51 MysqlndUhConnection::useResult
9.8 The MysqlndUhPreparedStatement class (MysqlndUhPreparedStatement)
9.8.1 MysqlndUhPreparedStatement::__construct
9.8.2 MysqlndUhPreparedStatement::execute
9.8.3 MysqlndUhPreparedStatement::prepare
9.9 Mysqlnd_uh Functions
9.9.1 mysqlnd_uh_convert_to_mysqlnd
9.9.2 mysqlnd_uh_set_connection_proxy
9.9.3 mysqlnd_uh_set_statement_proxy
9.10 Change History
9.10.1 PECL/mysqlnd_uh 1.0 series
10 Mysqlnd connection multiplexing plugin (mysqlnd_mux)
10.1 Key Features
10.2 Limitations
10.3 About the name mysqlnd_mux
10.4 Concepts
10.4.1 Architecture
10.4.2 Connection pool
10.4.3 Sharing connections
10.5 Installing/Configuring
10.5.1 Requirements
10.5.2 Installation
10.5.3 Runtime Configuration
10.6 Predefined Constants
10.7 Change History
10.7.1 PECL/mysqlnd_mux 1.0 series
11 Mysqlnd Memcache plugin (mysqlnd_memcache)
11.1 Key Features
11.2 Limitations
11.3 On the name
11.4 Quickstart and Examples
11.4.1 Setup
11.4.2 Usage
11.5 Installing/Configuring
11.5.1 Requirements
11.5.2 Installation
11.5.3 Runtime Configuration
11.6 Predefined Constants
11.7 Mysqlnd_memcache Functions
11.7.1 mysqlnd_memcache_get_config
11.7.2 mysqlnd_memcache_set
11.8 Change History
11.8.1 PECL/mysqlnd_memcache 1.0 series
12 Common Problems with MySQL and PHP