Tags: scheduling sprint stored procedure NEC vs into programming upgrade replacementfor a beginner PHP's own, the database connection has a lot of doubts, from Java to PHP. Database connection changed, previously only know JDBC Connection database, or directly with the framework call, for the PHP database connection method, and its application. Not very understanding, so consulted a lot of information and their actual operation, write down their own a little summary notes.
MySQL Extensions for PHP (pros and cons)
Design and development allows an early extension of PHP applications to interact with the MySQL database. The MySQL extension provides a process-oriented interface;
and is designed for MySQL4.1.3 or earlier versions. Thus, although this extension can be associated with MySQL4.1.3 or newer numbers;
The library server, but does not support some of the features provided by the post-MySQL server.
PHP mysqli Extensions
Mysqli extensions, which we sometimes call MySQL enhanced extensions, can be used for new advanced features in MySQL4.1.3 or newer versions;
Mysqli extensions are included in PHP 5 and later;
MYSQLI Extension has a series of advantages, compared to the MySQL extension is mainly: object-oriented interface, prepared statement support, multi-statement execution support, transaction support, enhanced debugging capabilities, embedded service support.
PHP Data Objects (PDO)
PHP Data Objects are a Database abstraction layer specification in PHP applications. PDO provides a unified API interface so that your PHP application does not care about the type of database server system you want to connect to. In other words, if you use the PDO API, you can seamlessly switch the database server whenever you need to.
Here are a few of the ways I've done this week for database connections:
Here are the differences between the three ways I see MySQL, mysqli, and PDO on the website
Php-mysql is the most primitive Extension of PHP operation MySQL Database, php-mysqli I represents improvement,
In addition to the relative advanced function, in terms of Extension, it also adds security.
The PDO (PHP Data Object) provides a abstraction Layer to manipulate the database
1.mysql and Mysqli
Mysqli is a new library of functions provided by PHP5, and (i) represents an improvement that executes faster. Of course it's safer.
MySQL is a non-holding connection function and Mysqli is a permanent connection function. Other words
MySQL each link will open a connected process and mysqli multiple runs mysqli will use the same connection process, thereby reducing the cost of the server some friends use new mysqli when programming (' localhost ', usenamer ', ' Password ', ' databasename ');
Wrong, Fatal Error:class ' mysqli ' not found in d:\ ...
Mysqli class is not PHP comes with it?
Not by default, win under to change php.ini, remove Php_mysqli.dll before, Linux to put Mysqli in.
One: Mysqli.dll is a database that allows the operation of objects in a way or process, and it is easy to use. Here are a few often
In fact, some knowledge behind ... This method can not Bind Column, the previous example of SQL narration, $location Place is easy to be SQL injection. Then the mysql_escape_string (note: 5.3.0) and mysql_real_escape_string () were developed to solve the problem, but the whole narrative would become complex and ugly, and if there were more columns, You can see what the situation is ...
There has been a lot of progress in php-mysqli, except through Bind Column to solve the above problems, but also Transaction, Multi Query,
It also provides an Object oriented style (the php-mysqli example below) and procedural style
But see here and found some shortcomings, such as Bind Result, this is a little bit more, but it does not matter, because the biggest problem is that this is not an abstract (abstraction) method, so when the backend to change the database, it is the beginning of pain ... And then PDO appeared.
2.PDO and MySQL
PDO was supported after PHP5.1, and he used a consistent interface for accessing the database. But many of the country's open source programs are
Use the function provided by MySQL extension to connect to the database for querying. PDO is powerful why is the domestic mature PHP system not used?
Asked a few friends why with PDO, the answer is "fast", PDO connection database will be fast? Why use PDO? What is the difference between the two ways? First of all, it is more concerned with performance issues. wrote 1 script tests to insert 1 million data into MySQL.
Use MySQL extension:95.233189106s
There's almost no difference in linking MySQL. The performance loss of PDO can be completely negligible.
But there are a lot of things that the MySQL extension library does not have:
1:pdo real-to-bottom implementation of the unified Interface number Library operation interface
2:PDO supports more advanced DB feature operations, such as the scheduling of stored procedures, which are not supported by MySQL native libraries.
3:pdo is the official PHP pecl library, compatibility stability is necessarily higher than the MySQL Extension, you can directly use the PECL Upgrade PDO command upgrade.
PHP6 The default is to use PDO for database links, MySQL extension will be used as a secondary. So in our daily projects, if the environment permits, use PDO as much as possible to perform MySQL database operations.
Reprint, please indicate the source and the corresponding link, this article Permanent address: http://blog.it985.com/3987.html
The usage and difference of MySQL, mysqli and PDO in PHP "original"