You may be wondering whether you should use mySQLi or use PDO. Above
this question, you have to know that PHP 5 as well as the later PHP is able to
work with mySQL database. They can work using the extension of mySQLi or PDO.
The additional “i” in mySQLi stands for the one improved, while PDO stands for
PHP data objects. mySQL extension was used in the earlier version of PHP. But,
in 2012 this type of extension was deprecated. The following description will
discuss mySQL examples in both mySQLi and PDO syntax.
PDO Installation and
mySQL Installation Guide
·
PDO installation
In the installation pdo_mySQL as shared module, you need to update the
file of php.ini in order to make PDO extension be automatically loaded when the
PHP runs. Besides, you should enable any specific drivers of database and make
sure carefully that they have been listed right after the line of pdo.so.
However, you can also skip this point or step if you build the specific extension
of database and PDO statistically. When you build PDO as shared extension, all
drivers of PDO have to be loaded right after the PDO itself. This kind of PDO
building is not recommended though.
·
mySQL installation
In term of mySQL installation guide, the distributions of Unix which are
considered as common one include the PHP binary versions which are also able to
be installed. Extension libraries of this binary version might need to be
installed by using additional package, although it is built typically with the
support for mySQL extensions. Therefore, you should check package manager that
comes along with your availability distribution. Moreover, you are allowed to
complete the extension by yourself.
You are also allowed to specify mySQL extensions that you like to use if
you built PHP from the sources. You could even specify your client library
choice of each extension. The recommended option of client library is mySQL
Native Driver. It has been improved in the performance and gives the access of
unavailable features in mySQL client library.
Open and Close
Connection in mySQL
·
Open the connection
Another important thing which should be understood within this tutorial
to connect PHP to mySQL is about to open a connection to mySQL PHP. You are
going to need the capability for connecting the server before being able in
accessing the data in mySQL database. PHP is quite popular and amazing
language. In PDO, you can also specified the database. PDO requires valid
database in order to connect. An exception will be thrown when there is no
specified database.
·
Close connection
The last point in this simple tutorial is regarding close the connection
in mySQL. If you are going to close the connection, it is going to be
automatically closed right when script has ended. There will be some kinds of
code used to close connection. The first example is mySQLi object-oriented. It
uses $conn->close();. The second example is PDO which uses $conn = null;. As
for the last example to close conncetion, it is mySQLi procedural example. It
uses mySQLi_close($conn);.
0 komentar:
Posting Komentar