Introduction to PHP's Built-In MYSQL Functions

If you are thinking "What is a database?" or "Why MYSQL?", head on over to our MYSQL Tutorial. There you will not only learn the answer to these questions, you will also learn the basic commands needed to use MYSQL.

Once you are up to speed you can begin to learn how to integrate MYSQL commands directly into your PHP code.

PHP's MYSQLI class has over 60 built-in functions to meet your MYSQL interfacing needs. Just about anything that you ever wanted to do (and a few that you didn't) can be done with one function or another, but we will, in the next few pages, only concentrate on the fourteen functions that are most suited to our needs:

Function Description
mysqli_affected_rows() Returns the number of affected rows in the previous MySQL operation
mysqli_close() Closes a previously opened database connection
mysqli_connect() Opens a new connection to the MySQL server
mysqli_errno() Returns the last error code for the most recent function call
mysqli_error() Returns the last error description for the most recent function call
mysqli_fetch_all() Fetches all result rows as an associative array, a numeric array, or both
mysqli_fetch_array() Fetches a result row as an associative, a numeric array, or both
mysqli_fetch_assoc() Fetches a result row as an associative array
mysqli_fetch_row() Fetches one row from a result-set and returns it as an enumerated array
mysqli_free_result() Frees the memory associated with a result
mysqli_num_rows() Returns the number of rows in a result set
mysqli_query() Performs a query against the database
mysqli_real_escape_string() Escapes special characters in a string for use in an SQL statement
mysqli_select_db() Changes the default database for the connection