MySQL PHP API

Abstract

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

For legal information, see the Legal Notices.

For help with using MySQL, please visit either the MySQL Forums or MySQL Mailing Lists, where you can discuss your issues with other MySQL users.

Document generated on: 2018-08-15 (revision: 58611)


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
3.1 Overview
3.2 Quick start guide
3.2.1 Dual procedural and object-oriented interface
3.2.2 Connections
3.2.3 Executing statements
3.2.4 Prepared Statements
3.2.5 Stored Procedures
3.2.6 Multiple Statements
3.2.7 API support for transactions
3.2.8 Metadata
3.3 Installing/Configuring
3.3.1 Requirements
3.3.2 Installation
3.3.3 Runtime Configuration
3.3.4 Resource Types
3.4 The mysqli Extension and Persistent Connections
3.5 Predefined Constants
3.6 Notes
3.7 The MySQLi Extension Function Summary
3.8 Examples
3.8.1 MySQLi extension basic examples
3.9 The mysqli class
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::close, mysqli_close
3.9.7 mysqli::commit, mysqli_commit
3.9.8 mysqli::$connect_errno, mysqli_connect_errno
3.9.9 mysqli::$connect_error, mysqli_connect_error
3.9.10 mysqli::__construct, mysqli::connect, mysqli_connect
3.9.11 mysqli::debug, mysqli_debug
3.9.12 mysqli::dump_debug_info, mysqli_dump_debug_info
3.9.13 mysqli::$errno, mysqli_errno
3.9.14 mysqli::$error_list, mysqli_error_list
3.9.15 mysqli::$error, mysqli_error
3.9.16 mysqli::$field_count, mysqli_field_count
3.9.17 mysqli::get_charset, mysqli_get_charset
3.9.18 mysqli::$client_info, mysqli::get_client_info, mysqli_get_client_info
3.9.19 mysqli::$client_version, mysqli_get_client_version
3.9.20 mysqli::get_connection_stats, mysqli_get_connection_stats
3.9.21 mysqli::$host_info, mysqli_get_host_info
3.9.22 mysqli::$protocol_version, mysqli_get_proto_info
3.9.23 mysqli::$server_info, mysqli::get_server_info, mysqli_get_server_info
3.9.24 mysqli::$server_version, mysqli_get_server_version
3.9.25 mysqli::get_warnings, mysqli_get_warnings
3.9.26 mysqli::$info, mysqli_info
3.9.27 mysqli::init, mysqli_init
3.9.28 mysqli::$insert_id, mysqli_insert_id
3.9.29 mysqli::kill, mysqli_kill
3.9.30 mysqli::more_results, mysqli_more_results
3.9.31 mysqli::multi_query, mysqli_multi_query
3.9.32 mysqli::next_result, mysqli_next_result
3.9.33 mysqli::options, mysqli_options
3.9.34 mysqli::ping, mysqli_ping
3.9.35 mysqli::poll, mysqli_poll
3.9.36 mysqli::prepare, mysqli_prepare
3.9.37 mysqli::query, mysqli_query
3.9.38 mysqli::real_connect, mysqli_real_connect
3.9.39 mysqli::real_escape_string, mysqli::escape_string, mysqli_real_escape_string
3.9.40 mysqli::real_query, mysqli_real_query
3.9.41 mysqli::reap_async_query, mysqli_reap_async_query
3.9.42 mysqli::refresh, mysqli_refresh
3.9.43 mysqli::release_savepoint, mysqli_release_savepoint
3.9.44 mysqli::rollback, mysqli_rollback
3.9.45 mysqli::rpl_query_type, mysqli_rpl_query_type
3.9.46 mysqli::savepoint, mysqli_savepoint
3.9.47 mysqli::select_db, mysqli_select_db
3.9.48 mysqli::send_query, mysqli_send_query
3.9.49 mysqli::set_charset, mysqli_set_charset
3.9.50 mysqli::set_local_infile_default, mysqli_set_local_infile_default
3.9.51 mysqli::set_local_infile_handler, mysqli_set_local_infile_handler
3.9.52 mysqli::$sqlstate, mysqli_sqlstate
3.9.53 mysqli::ssl_set, mysqli_ssl_set
3.9.54 mysqli::stat, mysqli_stat
3.9.55 mysqli::stmt_init, mysqli_stmt_init
3.9.56 mysqli::store_result, mysqli_store_result
3.9.57 mysqli::$thread_id, mysqli_thread_id
3.9.58 mysqli::thread_safe, mysqli_thread_safe
3.9.59 mysqli::use_result, mysqli_use_result
3.9.60 mysqli::$warning_count, mysqli_warning_count
3.10 The mysqli_stmt class
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::__construct
3.10.8 mysqli_stmt::data_seek, mysqli_stmt_data_seek
3.10.9 mysqli_stmt::$errno, mysqli_stmt_errno
3.10.10 mysqli_stmt::$error_list, mysqli_stmt_error_list
3.10.11 mysqli_stmt::$error, mysqli_stmt_error
3.10.12 mysqli_stmt::execute, mysqli_stmt_execute
3.10.13 mysqli_stmt::fetch, mysqli_stmt_fetch
3.10.14 mysqli_stmt::$field_count, mysqli_stmt_field_count
3.10.15 mysqli_stmt::free_result, mysqli_stmt_free_result
3.10.16 mysqli_stmt::get_result, mysqli_stmt_get_result
3.10.17 mysqli_stmt::get_warnings, mysqli_stmt_get_warnings
3.10.18 mysqli_stmt::$insert_id, mysqli_stmt_insert_id
3.10.19 mysqli_stmt::more_results, mysqli_stmt_more_results
3.10.20 mysqli_stmt::next_result, mysqli_stmt_next_result
3.10.21 mysqli_stmt::$num_rows, mysqli_stmt::num_rows, mysqli_stmt_num_rows
3.10.22 mysqli_stmt::$param_count, mysqli_stmt_param_count
3.10.23 mysqli_stmt::prepare, mysqli_stmt_prepare
3.10.24 mysqli_stmt::reset, mysqli_stmt_reset
3.10.25 mysqli_stmt::result_metadata, mysqli_stmt_result_metadata
3.10.26 mysqli_stmt::send_long_data, mysqli_stmt_send_long_data
3.10.27 mysqli_stmt::$sqlstate, mysqli_stmt_sqlstate
3.10.28 mysqli_stmt::store_result, mysqli_stmt_store_result
3.11 The mysqli_result class
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_result::close, mysqli_result::free_result, 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
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
3.13.1 mysqli_warning::__construct
3.13.2 mysqli_warning::next
3.14 The mysqli_sql_exception class
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_client_stats
3.15.14 mysqli_get_links_stats
3.15.15 mysqli_get_metadata
3.15.16 mysqli_master_query
3.15.17 mysqli_param_count
3.15.18 mysqli_report
3.15.19 mysqli_rpl_parse_enabled
3.15.20 mysqli_rpl_probe
3.15.21 mysqli_send_long_data
3.15.22 mysqli::set_opt, mysqli_set_opt
3.15.23 mysqli_slave_query
3.16 Changelog
4 MySQL Functions (PDO_MYSQL)
4.1 PDO_MYSQL DSN
5 Mysql_xdevapi
5.1 Installing/Configuring
5.1.1 Requirements
5.1.2 Installation
5.1.3 Runtime Configuration
5.2 Predefined Constants
5.3 Examples
5.4 Mysql_xdevapi Functions
5.4.1 expression
5.4.2 getSession
5.5 BaseResult interface
5.5.1 BaseResult::getWarnings
5.5.2 BaseResult::getWarningsCount
5.6 Collection class
5.6.1 Collection::add
5.6.2 Collection::addOrReplaceOne
5.6.3 Collection::__construct
5.6.4 Collection::count
5.6.5 Collection::createIndex
5.6.6 Collection::dropIndex
5.6.7 Collection::existsInDatabase
5.6.8 Collection::find
5.6.9 Collection::getName
5.6.10 Collection::getOne
5.6.11 Collection::getSchema
5.6.12 Collection::getSession
5.6.13 Collection::modify
5.6.14 Collection::remove
5.6.15 Collection::removeOne
5.6.16 Collection::replaceOne
5.7 CollectionAdd class
5.7.1 CollectionAdd::__construct
5.7.2 CollectionAdd::execute
5.8 CollectionFind class
5.8.1 CollectionFind::bind
5.8.2 CollectionFind::__construct
5.8.3 CollectionFind::execute
5.8.4 CollectionFind::fields
5.8.5 CollectionFind::groupBy
5.8.6 CollectionFind::having
5.8.7 CollectionFind::limit
5.8.8 CollectionFind::lockExclusive
5.8.9 CollectionFind::lockShared
5.8.10 CollectionFind::offset
5.8.11 CollectionFind::sort
5.9 CollectionModify class
5.9.1 CollectionModify::arrayAppend
5.9.2 CollectionModify::arrayInsert
5.9.3 CollectionModify::bind
5.9.4 CollectionModify::__construct
5.9.5 CollectionModify::execute
5.9.6 CollectionModify::limit
5.9.7 CollectionModify::patch
5.9.8 CollectionModify::replace
5.9.9 CollectionModify::set
5.9.10 CollectionModify::skip
5.9.11 CollectionModify::sort
5.9.12 CollectionModify::unset
5.10 CollectionRemove class
5.10.1 CollectionRemove::bind
5.10.2 CollectionRemove::__construct
5.10.3 CollectionRemove::execute
5.10.4 CollectionRemove::limit
5.10.5 CollectionRemove::sort
5.11 ColumnResult class
5.11.1 ColumnResult::__construct
5.11.2 ColumnResult::getCharacterSetName
5.11.3 ColumnResult::getCollationName
5.11.4 ColumnResult::getColumnLabel
5.11.5 ColumnResult::getColumnName
5.11.6 ColumnResult::getFractionalDigits
5.11.7 ColumnResult::getLength
5.11.8 ColumnResult::getSchemaName
5.11.9 ColumnResult::getTableLabel
5.11.10 ColumnResult::getTableName
5.11.11 ColumnResult::getType
5.11.12 ColumnResult::isNumberSigned
5.11.13 ColumnResult::isPadded
5.12 CrudOperationBindable interface
5.12.1 CrudOperationBindable::bind
5.13 CrudOperationLimitable interface
5.13.1 CrudOperationLimitable::limit
5.14 CrudOperationSkippable interface
5.14.1 CrudOperationSkippable::skip
5.15 CrudOperationSortable interface
5.15.1 CrudOperationSortable::sort
5.16 DatabaseObject interface
5.16.1 DatabaseObject::existsInDatabase
5.16.2 DatabaseObject::getName
5.16.3 DatabaseObject::getSession
5.17 DocResult class
5.17.1 DocResult::__construct
5.17.2 DocResult::fetchAll
5.17.3 DocResult::fetchOne
5.17.4 DocResult::getWarnings
5.17.5 DocResult::getWarningsCount
5.18 Driver class
5.18.1 Driver::__construct
5.19 Exception class
5.20 Executable interface
5.20.1 Executable::execute
5.21 ExecutionStatus class
5.21.1 ExecutionStatus::__construct
5.22 Expression class
5.22.1 Expression::__construct
5.23 FieldMetadata class
5.23.1 FieldMetadata::__construct
5.24 Result class
5.24.1 Result::__construct
5.24.2 Result::getAutoIncrementValue
5.24.3 Result::getGeneratedIds
5.24.4 Result::getWarnings
5.24.5 Result::getWarningsCount
5.25 RowResult class
5.25.1 RowResult::__construct
5.25.2 RowResult::fetchAll
5.25.3 RowResult::fetchOne
5.25.4 RowResult::getColumnCount
5.25.5 RowResult::getColumnNames
5.25.6 RowResult::getColumns
5.25.7 RowResult::getWarnings
5.25.8 RowResult::getWarningsCount
5.26 Schema class
5.26.1 Schema::__construct
5.26.2 Schema::createCollection
5.26.3 Schema::dropCollection
5.26.4 Schema::existsInDatabase
5.26.5 Schema::getCollection
5.26.6 Schema::getCollectionAsTable
5.26.7 Schema::getCollections
5.26.8 Schema::getName
5.26.9 Schema::getSession
5.26.10 Schema::getTable
5.26.11 Schema::getTables
5.27 SchemaObject interface
5.27.1 SchemaObject::getSchema
5.28 Session class
5.28.1 Session::close
5.28.2 Session::commit
5.28.3 Session::__construct
5.28.4 Session::createSchema
5.28.5 Session::dropSchema
5.28.6 Session::executeSql
5.28.7 Session::generateUUID
5.28.8 Session::getClientId
5.28.9 Session::getSchema
5.28.10 Session::getSchemas
5.28.11 Session::getServerVersion
5.28.12 Session::killClient
5.28.13 Session::listClients
5.28.14 Session::quoteName
5.28.15 Session::releaseSavepoint
5.28.16 Session::rollback
5.28.17 Session::rollbackTo
5.28.18 Session::setSavepoint
5.28.19 Session::sql
5.28.20 Session::startTransaction
5.29 SqlStatement class
5.29.1 SqlStatement::bind
5.29.2 SqlStatement::__construct
5.29.3 SqlStatement::execute
5.29.4 SqlStatement::getNextResult
5.29.5 SqlStatement::getResult
5.29.6 SqlStatement::hasMoreResults
5.30 SqlStatementResult class
5.30.1 SqlStatementResult::__construct
5.30.2 SqlStatementResult::fetchAll
5.30.3 SqlStatementResult::fetchOne
5.30.4 SqlStatementResult::getAffectedItemsCount
5.30.5 SqlStatementResult::getColumnCount
5.30.6 SqlStatementResult::getColumnNames
5.30.7 SqlStatementResult::getColumns
5.30.8 SqlStatementResult::getGeneratedIds
5.30.9 SqlStatementResult::getLastInsertId
5.30.10 SqlStatementResult::getWarnings
5.30.11 SqlStatementResult::getWarningsCount
5.30.12 SqlStatementResult::hasData
5.30.13 SqlStatementResult::nextResult
5.31 Statement class
5.31.1 Statement::__construct
5.31.2 Statement::getNextResult
5.31.3 Statement::getResult
5.31.4 Statement::hasMoreResults
5.32 Table class
5.32.1 Table::__construct
5.32.2 Table::count
5.32.3 Table::delete
5.32.4 Table::existsInDatabase
5.32.5 Table::getName
5.32.6 Table::getSchema
5.32.7 Table::getSession
5.32.8 Table::insert
5.32.9 Table::isView
5.32.10 Table::select
5.32.11 Table::update
5.33 TableDelete class
5.33.1 TableDelete::bind
5.33.2 TableDelete::__construct
5.33.3 TableDelete::execute
5.33.4 TableDelete::limit
5.33.5 TableDelete::offset
5.33.6 TableDelete::orderby
5.33.7 TableDelete::where
5.34 TableInsert class
5.34.1 TableInsert::__construct
5.34.2 TableInsert::execute
5.34.3 TableInsert::values
5.35 TableSelect class
5.35.1 TableSelect::bind
5.35.2 TableSelect::__construct
5.35.3 TableSelect::execute
5.35.4 TableSelect::groupBy
5.35.5 TableSelect::having
5.35.6 TableSelect::limit
5.35.7 TableSelect::lockExclusive
5.35.8 TableSelect::lockShared
5.35.9 TableSelect::offset
5.35.10 TableSelect::orderby
5.35.11 TableSelect::where
5.36 TableUpdate class
5.36.1 TableUpdate::bind
5.36.2 TableUpdate::__construct
5.36.3 TableUpdate::execute
5.36.4 TableUpdate::limit
5.36.5 TableUpdate::orderby
5.36.6 TableUpdate::set
5.36.7 TableUpdate::where
5.37 Warning class
5.37.1 Warning::__construct
5.38 XSession class
5.38.1 XSession::__construct
6 Original MySQL API
6.1 Installing/Configuring
6.1.1 Requirements
6.1.2 Installation
6.1.3 Runtime Configuration
6.1.4 Resource Types
6.2 Changelog
6.3 Predefined Constants
6.4 Examples
6.4.1 MySQL extension overview example
6.5 MySQL Functions
6.5.1 mysql_affected_rows
6.5.2 mysql_client_encoding
6.5.3 mysql_close
6.5.4 mysql_connect
6.5.5 mysql_create_db
6.5.6 mysql_data_seek
6.5.7 mysql_db_name
6.5.8 mysql_db_query
6.5.9 mysql_drop_db
6.5.10 mysql_errno
6.5.11 mysql_error
6.5.12 mysql_escape_string
6.5.13 mysql_fetch_array
6.5.14 mysql_fetch_assoc
6.5.15 mysql_fetch_field
6.5.16 mysql_fetch_lengths
6.5.17 mysql_fetch_object
6.5.18 mysql_fetch_row
6.5.19 mysql_field_flags
6.5.20 mysql_field_len
6.5.21 mysql_field_name
6.5.22 mysql_field_seek
6.5.23 mysql_field_table
6.5.24 mysql_field_type
6.5.25 mysql_free_result
6.5.26 mysql_get_client_info
6.5.27 mysql_get_host_info
6.5.28 mysql_get_proto_info
6.5.29 mysql_get_server_info
6.5.30 mysql_info
6.5.31 mysql_insert_id
6.5.32 mysql_list_dbs
6.5.33 mysql_list_fields
6.5.34 mysql_list_processes
6.5.35 mysql_list_tables
6.5.36 mysql_num_fields
6.5.37 mysql_num_rows
6.5.38 mysql_pconnect
6.5.39 mysql_ping
6.5.40 mysql_query
6.5.41 mysql_real_escape_string
6.5.42 mysql_result
6.5.43 mysql_select_db
6.5.44 mysql_set_charset
6.5.45 mysql_stat
6.5.46 mysql_tablename
6.5.47 mysql_thread_id
6.5.48 mysql_unbuffered_query
7 MySQL Native Driver
7.1 Overview
7.2 Installation
7.3 Runtime Configuration
7.4 Incompatibilities
7.5 Persistent Connections
7.6 Statistics
7.7 Notes
7.8 Memory management
7.9 MySQL Native Driver Plugin API
7.9.1 A comparison of mysqlnd plugins with MySQL Proxy
7.9.2 Obtaining the mysqlnd plugin API
7.9.3 MySQL Native Driver Plugin Architecture
7.9.4 The mysqlnd plugin API
7.9.5 Getting started building a mysqlnd plugin
8 Common Problems with MySQL and PHP
';