Moving from mysql to mysqli or pdo? [closed]

2020-01-29 08:14发布

Duplicate: mysqli or PDO - what are the pros and cons?

I'm looking to move a website from mysql to either mysqli or pdo as primarily a learning tool, but also for performance increases if possible.

I have read through http://php.net/manual/en/mysqli.overview.php and it seems like both would suit my needs, but it doesn't lean strongly either way.

The site currently uses primarily non object orientated code, but I do have experience with OO in other languages. A huge majority of the queries are simple complex select statements with very little update/inserts. What do you suggest as being the most useful both from my own education and for this specific site?

If you need any additional information please let me know.

Thanks.

5条回答
成全新的幸福
2楼-- · 2020-01-29 08:20

PDO Pro's:

  • Native to PHP as of 5.x
  • Supports named parameters as opposed to numerically indexed ?'s
  • Same abstraction library supports multiple different RDBM's

Mysqli Con's:

  • Has issues with properly storing and retrieving large objects in the database.
  • No support for named parameters.

Otherwise, both libraries are basically different flavors of the same thing. They both have functions to quote parameters and both support parameterized queries.

If none of the above arguments sway you, then go with whichever library you prefer based on its syntax, style, etc.

查看更多
▲ chillily
3楼-- · 2020-01-29 08:20

I don't believe PDO would give you any performance increase, but it gives you these two very attractive long-term benefits:

  • you can scale your app to use other databases with just a few code changes
  • the PDO library has much of the security built in

If you don't understand the benefits to #1 and #2, then just stick with the tried-and-true mysql library (you are at least using mysql_real_escape_string though, right)?

If I were learning a new PHP database library, I believe PDO is the way to go, especially if you are creating a web app that may be used on a variety of systems other than your own server.

查看更多
Melony?
4楼-- · 2020-01-29 08:29

PDO offer great security than other without much hassle, but for transition i would suggest you to move to mysqli since it faster, easier than PDO, and most api/syntax are quite same with the old mysql extension

See here (scroll below) for quick comparisson:
PHP & MySQLi

Edit: Looks like it same link as you've read before, sorry

查看更多
甜甜的少女心
5楼-- · 2020-01-29 08:44

From http://www.php.net/manual/en/mysqli.overview.php :

While PDO has its advantages, such as a clean, simple, portable API, its main disadvantage is that it doesn't allow you to use all of the advanced features that are available in the latest versions of MySQL server. For example, PDO does not allow you to use MySQL's support for Multiple Statements.

查看更多
beautiful°
6楼-- · 2020-01-29 08:44

When building my ORM and abstraction library I used MySQLi and PDO to see which one performs better. MySQLi was faster - but not enough to make the choice based on that alone.

One thing that MySQLi/MySQL/SQLite or any of the other independent libraries have over PDO is that they return the number of rows found in the result which often helps to test for any results at all. Meanwhile, in PDO you either fetchAll() results and count() them - or run a count query before to see the number of results. So you have to adapt to handle this problem in different ways.

Oh, and I choose PDO over MySQLi in the end.

查看更多
登录 后发表回答