PHP – MySQLi Extension
This is one of many extensions that PHP has to communicate with databases. It is more than clear that this extension is for communicating with MySQL-type DBMS, and the ‘i’ in its name stands for ‘improved,’ meaning enhanced.
Introduction
In this post, we will see what the extension consists of, so we won’t see much code.
Firstly, and most importantly, this extension has 6 classes, which are:
mysqli
mysqli_stmt
mysqli_result
mysql_driver
mysql_warning
mysqli_sql_exception
Then we have a bunch of functions to interact with these classes, which I won’t touch on, as I believe they only clutter any code.
This is because you lose any reference to what you’re doing and are left thinking, ‘What?’, ‘Why does this work?’, or ‘Why doesn’t this work?’
As for whether you can do things without using these functions, I will tell you that you can do everything. They are just interfaces to use some method within the classes we saw earlier.
Why do they exist? This is for those who want to write their code procedurally and not in an object-oriented way. Their existence is only due to earlier versions of PHP.
Classes that shapes the mysqli extension
In this section, we will see a brief summary of what the classes that are part of the extension do.
mysqli
It represents a connection between PHP and MySQL, and it also creates the connection when using its constructor.
mysqli_stmt
This class represents a prepared statement, and that’s why it’s _stmt
. With it, you can handle all types of queries that have been created with the prepare()
method of the mysqli
class.
mysqli_result
It represents a result after making a query to MySQL.
mysql_driver
Driver, it is likely that in a typical project, you won’t interact with this class directly.
mysql_warning
Warnings that MySQL may give after executing a query.
mysqli_sql_exception
Handling of exceptions that MySQL may throw after executing a query.