PHP MySQLi is how beginners talk to a MySQL or MariaDB database from PHP. You open a link, set the character set, run SQL, read each row, check for errors, and close the connection when you are finished.
With $mysqli = new mysqli(...) you write $mysqli->set_charset('utf8mb4'), $mysqli->query($sql), $result->fetch_assoc(), and $mysqli->close(). The ideas match the procedural names on this page.
Map
Function Groups at a Glance
The MySQLi section is one family with several jobs. Use this map to pick the right group before you open a function page:
Group
Typical job
Start here
Connect & options
Open a link, set options/SSL/charset, switch DB, ping, close
Neighboring tutorials that often sit next to this work: Network for headers and sockets, Variables for types and casting, JSON for API payloads beside database rows, and Strings for text you store or display.
Code
PHP Examples
Three short scripts that show the core MySQLi ideas. Sample outputs below match a typical local setup so you can study the flow without a live database. Each block includes a fixed View Output panel that matches this tutorial layout.
Example 1 — Connect, charset, and errors
Open a link, check connect_errno / connect_error, set utf8mb4, then close.
MySQLi (MySQL Improved) is PHP's extension for talking to a MySQL or MariaDB server. You open a connection, set a character set, run SQL with query() or prepare(), read rows with fetch helpers, check errors with connect_error or errno, and close when you are done.
Start with mysqli_connect() (or new mysqli()), then mysqli_set_charset(), then a simple mysqli_query() plus mysqli_fetch_assoc() loop. After that, learn mysqli_prepare() for user input, and always check mysqli_connect_error() or mysqli_errno() before you trust a result.
mysqli_query() sends a finished SQL string. mysqli_prepare() builds a statement with placeholders (?), then you bind values and execute. Prefer prepare() whenever values come from the user—it helps avoid SQL injection. For fixed SQL with no user data, query() is fine.
After connect, check mysqli_connect_error() (string) or mysqli_connect_errno() (number). On an open link, mysqli_error() and mysqli_errno() report the last query error. Stop and show a safe message if connect failed—do not run queries on a bad link.
mysqli_execute_query() (PHP 8.2) prepares, binds, and executes in one call and returns a result. mysqli_fetch_column() (PHP 8.1) returns one column from the next row. Confirm function_exists() if you support older PHP.
Both call the same extension. Procedural names look like mysqli_query($link, $sql). Object style uses $mysqli->query($sql). This tutorial shows both patterns; pick one style and stay consistent in a project.