PHP MySQLi Functions

About This Index
This page is the PHP MySQLi Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn how connect, charset, query vs prepare, fetch, and close fit together on /php/mysqli. Use this page when you need a specific function such as mysqli_connect(), mysqli_query(), or mysqli_fetch_assoc().
Start with mysqli_connect() and mysqli_set_charset()—then learn mysqli_query(), mysqli_fetch_assoc(), and mysqli_prepare(), and always check mysqli_connect_error() / mysqli_errno().
Alias pages are included so the sidebar list is complete (escape_string → real_escape_string, set_opt → options). Prefer the primary name in new code. mysqli_execute_query() (PHP 8.2) and mysqli_fetch_column() (PHP 8.1) are marked in the tables below.
How to Call a PHP MySQLi Function
Procedural MySQLi helpers are global functions—pass the link (or result) as the first argument. Set charset after connect; close when you are done:
$link = mysqli_connect('127.0.0.1', 'user', 'pass', 'db');
if (mysqli_connect_errno()) {
die(mysqli_connect_error());
}
mysqli_set_charset($link, 'utf8mb4');
$result = mysqli_query($link, 'SELECT id, name FROM users LIMIT 5');
while ($row = mysqli_fetch_assoc($result)) {
echo $row['name'], PHP_EOL;
}
// Prefer prepare() for user values
// $stmt = mysqli_prepare($link, 'SELECT name FROM users WHERE id = ?');
mysqli_close($link); PHP MySQLi Functions Table
All function guides in this PHP tutorial series (77 tutorials in 8 categories).
Connect & options
11 functionsOpen a connection, set options or SSL before connect, switch user or database, set charset, ping the server, and close when you are done.
| Function | Description | Tutorial |
|---|---|---|
mysqli_change_user() | Change the user of an open connection. | Try it |
mysqli_close() | Close a previously opened database connection. | Try it |
mysqli_connect() | Open a new connection to the MySQL server. | Try it |
mysqli_init() | Initialize MySQLi and return a handle for real_connect(). | Try it |
mysqli_options() | Set options before real_connect(). | Try it |
mysqli_ping() | Ping the server connection, or reconnect if needed. | Try it |
mysqli_real_connect() | Open a connection using an init() handle and options. | Try it |
mysqli_select_db() | Select the default database for queries. | Try it |
mysqli_set_charset() | Set the default client character set (e.g. utf8mb4). | Try it |
mysqli_set_opt() | Alias of mysqli_options(): set connection options. | Try it |
mysqli_ssl_set() | Set SSL parameters used by real_connect(). | Try it |
Errors & info
10 functionsRead connect and query errors, SQLSTATE, warnings, and last-query info strings from the server.
| Function | Description | Tutorial |
|---|---|---|
mysqli_connect_errno() | Return the error code from the last connect call. | Try it |
mysqli_connect_error() | Return the error message from the last connect call. | Try it |
mysqli_errno() | Return the error code for the most recent function call. | Try it |
mysqli_error() | Return the error message for the most recent function call. | Try it |
mysqli_error_list() | Return a list of errors from the last command. | Try it |
mysqli_get_warnings() | Get the result set of SHOW WARNINGS. | Try it |
mysqli_info() | Return information about the last query. | Try it |
mysqli_sqlstate() | Return the SQLSTATE error code from the last error. | Try it |
mysqli_stat() | Return the current system status string. | Try it |
mysqli_warning_count() | Return the number of warnings from the last query. | Try it |
Query & results
18 functionsRun SQL with query, real_query, multi_query, or prepare; store or use results; track affected rows, insert id, and field metadata.
| Function | Description | Tutorial |
|---|---|---|
mysqli_affected_rows() | Get the number of affected rows from the last query. | Try it |
mysqli_current_field() | Get the current field offset of a result pointer. | Try it |
mysqli_data_seek() | Move the result pointer to an arbitrary row number. | Try it |
mysqli_execute_query() | Prepare, bind, and execute a query in one call (PHP 8.2). | Try it |
mysqli_field_count() | Get the number of columns for the most recent query. | Try it |
mysqli_field_seek() | Set the field cursor to a given offset. | Try it |
mysqli_free() | Free memory associated with a result. | Try it |
mysqli_insert_id() | Return the auto-generated id from the last INSERT. | Try it |
mysqli_more_results() | Check whether more results exist from multi_query(). | Try it |
mysqli_multi_query() | Perform one or more queries against the database. | Try it |
mysqli_next_result() | Prepare the next result set from multi_query(). | Try it |
mysqli_num_rows() | Get the number of rows in a result. | Try it |
mysqli_prepare() | Prepare an SQL statement for execution. | Try it |
mysqli_query() | Perform a query on the database. | Try it |
mysqli_real_query() | Execute a query; pair with store_result() or use_result(). | Try it |
mysqli_stmt_init() | Initialize a statement object for prepare(). | Try it |
mysqli_store_result() | Transfer a result set from the last query. | Try it |
mysqli_use_result() | Initiate a result set retrieval without buffering all rows. | Try it |
Fetch
10 functionsRead rows and field metadata from a result: associative arrays, numeric rows, objects, one column, or field info.
| Function | Description | Tutorial |
|---|---|---|
mysqli_fetch_all() | Fetch all result rows as an array. | Try it |
mysqli_fetch_array() | Fetch a result row as an associative, numeric, or both. | Try it |
mysqli_fetch_assoc() | Fetch a result row as an associative array. | Try it |
mysqli_fetch_column() | Fetch a single column from the next row (PHP 8.1). | Try it |
mysqli_fetch_field() | Return the next field in the result set. | Try it |
mysqli_fetch_field_direct() | Fetch metadata for a single field as an object. | Try it |
mysqli_fetch_fields() | Return an array of objects representing the fields. | Try it |
mysqli_fetch_lengths() | Return the lengths of the columns of the current row. | Try it |
mysqli_fetch_object() | Fetch a result row as an object. | Try it |
mysqli_fetch_row() | Fetch a result row as an enumerated array. | Try it |
Transactions
6 functionsTurn autocommit on or off, begin a transaction, commit or roll back, and manage savepoints.
| Function | Description | Tutorial |
|---|---|---|
mysqli_autocommit() | Turn on or off auto-committing database modifications. | Try it |
mysqli_begin_transaction() | Start a transaction. | Try it |
mysqli_commit() | Commit the current transaction. | Try it |
mysqli_release_savepoint() | Remove a named savepoint from the current transaction. | Try it |
mysqli_rollback() | Roll back the current transaction. | Try it |
mysqli_savepoint() | Set a named transaction savepoint. | Try it |
Escape & charset
5 functionsEscape strings for legacy SQL building, and inspect the connection character set. Prefer prepare() for user input.
| Function | Description | Tutorial |
|---|---|---|
mysqli_character_set_name() | Return the current character set of the connection. | Try it |
mysqli_escape_string() | Alias of mysqli_real_escape_string(). | Try it |
mysqli_get_charset() | Return a character set object for the connection. | Try it |
mysqli_quote_string() | Escape and quote a string for use in SQL. | Try it |
mysqli_real_escape_string() | Escape special characters in a string for SQL. | Try it |
Client / server info & stats
11 functionsRead client and server version strings, host and protocol info, connection stats, and thread helpers.
| Function | Description | Tutorial |
|---|---|---|
mysqli_get_client_info() | Return the MySQL client library version as a string. | Try it |
mysqli_get_client_stats() | Return client per-process statistics. | Try it |
mysqli_get_client_version() | Return the MySQL client version as an integer. | Try it |
mysqli_get_connection_stats() | Return statistics about the client connection. | Try it |
mysqli_get_host_info() | Return a string describing the connection type. | Try it |
mysqli_get_links_stats() | Return information about open and cached links. | Try it |
mysqli_get_proto_info() | Return the version of the MySQL protocol used. | Try it |
mysqli_get_server_info() | Return the MySQL server version as a string. | Try it |
mysqli_get_server_version() | Return the MySQL server version as an integer. | Try it |
mysqli_thread_id() | Return the thread ID for the current connection. | Try it |
mysqli_thread_safe() | Return whether the client library is thread-safe. | Try it |
Async & advanced
6 functionsPoll asynchronous queries, reap results, kill threads, refresh server caches, and dump debug information.
| Function | Description | Tutorial |
|---|---|---|
mysqli_debug() | Perform debugging operations. | Try it |
mysqli_dump_debug_info() | Dump debugging information into the log. | Try it |
mysqli_kill() | Ask the server to kill a MySQL thread. | Try it |
mysqli_poll() | Poll connections for asynchronous query completion. | Try it |
mysqli_reap_async_query() | Get the result from an asynchronous query. | Try it |
mysqli_refresh() | Flush tables or caches on the server. | Try it |
Frequently Asked Questions
Start with mysqli_affected_rows()
Open the next guide—syntax, examples, and FAQs.
7 people found this page helpful
