Oracle 5.0 Reference Manual page 2251

Table of Contents

Advertisement

Overview of the MySQL PHP drivers
applications that need to communicate with databases the necessary APIs are usually exposed via
PHP extensions.
APIs can be procedural or object-oriented. With a procedural API you call functions to carry out tasks,
with the object-oriented API you instantiate classes and then call methods on the resulting objects. Of
the two the latter is usually the preferred interface, as it is more modern and leads to better organized
code.
When writing PHP applications that need to connect to the MySQL server there are several API options
available. This document discusses what is available and how to select the best solution for your
application.
What is a Connector?
In the MySQL documentation, the term connector refers to a piece of software that allows your
application to connect to the MySQL database server. MySQL provides connectors for a variety of
languages, including PHP.
If your PHP application needs to communicate with a database server you will need to write PHP
code to perform such activities as connecting to the database server, querying the database and other
database-related functions. Software is required to provide the API that your PHP application will use,
and also handle the communication between your application and the database server, possibly using
other intermediate libraries where necessary. This software is known generically as a connector, as it
allows your application to connect to a database server.
What is a Driver?
A driver is a piece of software designed to communicate with a specific type of database server. The
driver may also call a library, such as the MySQL Client Library or the MySQL Native Driver. These
libraries implement the low-level protocol used to communicate with the MySQL database server.
By way of an example, the
PHP Data Objects (PDO) [2309]
database abstraction layer may use one of
several database-specific drivers. One of the drivers it has available is the PDO MYSQL driver, which
allows it to interface with the MySQL server.
Sometimes people use the terms connector and driver interchangeably, this can be confusing. In the
MySQL-related documentation the term "driver" is reserved for software that provides the database-
specific part of a connector package.
What is an Extension?
In the PHP documentation you will come across another term - extension. The PHP code consists of a
core, with optional extensions to the core functionality. PHP's MySQL-related extensions, such as the
extension, and the
extension, are implemented using the PHP extension framework.
mysqli
mysql
An extension typically exposes an API to the PHP programmer, to allow its facilities to be used
programmatically. However, some extensions which use the PHP extension framework do not expose
an API to the PHP programmer.
The PDO MySQL driver extension, for example, does not expose an API to the PHP programmer, but
provides an interface to the PDO layer above it.
The terms API and extension should not be taken to mean the same thing, as an extension may not
necessarily expose an API to the programmer.
20.7.1.3. Choosing an API
Copyright 1997-2012 the PHP Documentation Group. [2230]
PHP offers three different APIs to connect to MySQL. Below we show the APIs provided by the mysql,
mysqli, and PDO extensions. Each code snippet creates a connection to a MySQL server running on
2231

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents