Database
connection in PHP (How to store data in Mysql database using php).
There are (more than) three
popular ways to use MySQL from PHP.
- (DEPRECATED)
The mysql functions are procedural and use
manual escaping.
- MySQLi is a replacement for the mysql
functions, with object-oriented and procedural versions. It has support
for prepared statements.
- PDO (PHP
Data Objects) is a general database abstraction layer with support for
MySQL among many other databases. It provides prepared statements, and
significant flexibility in how data is returned.
I would recommend using PDO with prepared statements. It is a
well-designed API and will let you more easily move to another database
(including any that supports ODBC) if necessary.
PDO is a database access tool in PHP which enables uniform access
across multiple databases. It does not support syntaxes specific to databases,
but it permits relatively seamless switching between different platforms and
databases, which can simply be done by changing the connection string.
The PHP Data Objects (PDO) extension defines a
lightweight, consistent interface for accessing databases in PHP. Each database
driver that implements the PDO interface can expose database-specific features
as regular extension functions. Note that you cannot perform any database
functions using the PDO extension by itself; you must use a database-specific
PDO driver to access a database server.
PDO provides a data-access abstraction layer, which means that,
regardless of which database you're using, you use the same functions to issue
queries and fetch data. The PDO extension has the capability to access any
database which the PDO driver has been written for. There are many PDO drivers
available, a few of which include PDO drivers meant to access Free TDS, Sybase,
Microsoft SQL Server, IBM DB2, Firebird/Interbase 6, Oracle Call Interface and
PostgreSQL databases, among many more.
PDO ships with PHP 5.1, and is available as a PECL extension for
PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not
run with earlier versions of PHP.
No comments:
Post a Comment