Reputation: 1979
Disclaimer: this question is strictly about mysql and database abstraction layers that support it.
The PHP website notes that using the mysql_
functions of PHP is highlighy discouraged. It instead encourages developers to use PDO
or MySQLi
.
Here's my question: in regards to mysql, under all the abstraction, are PDO and MySQLi just being a safer, more object-oriented wrapper for the mysql_
functions?
And if that's true, aren't frameworks like CodeIgniter and Symfony creating an unnecessary amount of wrappage by putting a layer on top of MySQLi which would then put a layer on top of native PHP mysql_
?
If it isn't true, I want to know why an experienced developer is discouraged from using mysql_
and what PDO
and MySQLi
actually do under the abstraction.
(Also, please don't tell me to go look at the code) Will give +100 bounty.
Upvotes: 4
Views: 379
Reputation: 18859
Here's my question: in regards to mysql, under all the abstraction, are PDO and MySQLi just being a safer, more object-oriented wrapper for the mysql_ functions?
No. Like xdazz said, both MySQLi and PDO are implemented in C, which means they don't just wrap the mysql_* functions.
And if that's true, aren't frameworks like CodeIgniter and Symfony creating an unnecessary amount of wrappage by putting a layer on top of MySQLi which would then put a layer on top of native PHP mysql_?
There's another reason to consider: CodeIgniter and Symfony probably created an interface over the default interface, because the default interface isn't usable enough (from their point of view). I myself have written a layer over PDO which sets some default settings (such as error-mode, as PDO is quiet by default) and makes a more intuitive API altogether. PDO is a very decent piece of software, but the setAttribute( $attr, $value )
just isn't my cup of tea, really.
Upvotes: 2
Reputation: 6718
PDO
and MySQLi
fucnctions and class methods are bindings to C-level API. Generally it is recommended to use this functions because of prepared statements: in PDO, in MySQLi. Using prepared statements is a good way to prevent SQL injections.
Upvotes: 2
Reputation: 160853
No, PDO and MySQLi are not wrapper of mysql_
functions, they are implemented in C level, different extensions.
Just think, if they are wrappers, --with-mysqli
and so on is not necessary.
Upvotes: 1