从mysql迁移到mysqli或pdo?

时间:2022-01-13 19:23:59

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.

我希望将一个网站从mysql转移到mysqli或pdo,作为主要的学习工具,但如果可能的话,性能也会提高。

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.

我已经阅读了http://php.net/manual/en/mysqli.overview.php,看起来两者都适合我的需求,但两者都不太适合。

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?

该站点目前主要使用非面向对象的代码,但我确实有使用其他语言的OO的经验。大多数查询都是简单复杂的select语句,几乎没有什么更新/插入。你认为在我的教育和这个网站上,什么是最有用的?

If you need any additional information please let me know.

如果你需要更多的信息,请告诉我。

Thanks.

谢谢。

5 个解决方案

#1


20  

PDO Pro's:

PDO职业:

  • Native to PHP as of 5.x
  • 本地的PHP是5。x。
  • Supports named parameters as opposed to numerically indexed ?'s
  • 支持命名参数,而不是数字索引?
  • Same abstraction library supports multiple different RDBM's
  • 相同的抽象库支持多个不同的rdbms

Mysqli Con's:

Mysqli反对:

  • 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.

如果上面的参数都没有影响到您,那么根据语法、样式等选择您喜欢的库。

#2


9  

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

我不认为PDO会给你带来任何业绩增长,但它会给你这两个非常有吸引力的长期利益:

  • 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
  • PDO库内置了许多安全性

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)?

如果您不理解#1和#2的好处,那么只需坚持使用试用的mysql库(至少您使用的是mysql_real_escape_string,对吧)?

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.

如果我正在学习一个新的PHP数据库库,我相信PDO是一种方法,特别是如果您正在创建一个web应用程序,它可以在您自己的服务器之外的各种系统上使用。

#3


8  

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

从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.

虽然PDO有它的优点,例如干净、简单、可移植的API,但是它的主要缺点是它不允许您使用MySQL服务器最新版本中可用的所有高级特性。例如,PDO不允许对多个语句使用MySQL的支持。

#4


4  

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

PDO提供了比其他的更好的安全性,没有太多麻烦,但是对于过渡,我建议您转移到mysqli,因为它比PDO更快、更容易,而且大多数api/语法与旧的mysql扩展是完全相同的

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

查看这里(在下面的滚动中)快速比较:PHP和MySQLi

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

编辑:看起来和你之前读过的链接一样,抱歉

#5


1  

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.

在构建我的ORM和抽象库时,我使用MySQLi和PDO来查看哪个性能更好。MySQLi的速度更快,但仅凭它还不足以做出选择。

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.

sqmyli /MySQL/SQLite或任何其他独立库在PDO上有一点是,它们返回结果中找到的行数,这通常有助于测试任何结果。同时,在PDO中,您可以获取结果并计数()——或者在查看结果数量之前运行一个计数查询。所以你必须适应以不同的方式处理这个问题。

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

哦,最后我选择PDO除以MySQLi。

#1


20  

PDO Pro's:

PDO职业:

  • Native to PHP as of 5.x
  • 本地的PHP是5。x。
  • Supports named parameters as opposed to numerically indexed ?'s
  • 支持命名参数,而不是数字索引?
  • Same abstraction library supports multiple different RDBM's
  • 相同的抽象库支持多个不同的rdbms

Mysqli Con's:

Mysqli反对:

  • 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.

如果上面的参数都没有影响到您,那么根据语法、样式等选择您喜欢的库。

#2


9  

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

我不认为PDO会给你带来任何业绩增长,但它会给你这两个非常有吸引力的长期利益:

  • 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
  • PDO库内置了许多安全性

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)?

如果您不理解#1和#2的好处,那么只需坚持使用试用的mysql库(至少您使用的是mysql_real_escape_string,对吧)?

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.

如果我正在学习一个新的PHP数据库库,我相信PDO是一种方法,特别是如果您正在创建一个web应用程序,它可以在您自己的服务器之外的各种系统上使用。

#3


8  

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

从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.

虽然PDO有它的优点,例如干净、简单、可移植的API,但是它的主要缺点是它不允许您使用MySQL服务器最新版本中可用的所有高级特性。例如,PDO不允许对多个语句使用MySQL的支持。

#4


4  

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

PDO提供了比其他的更好的安全性,没有太多麻烦,但是对于过渡,我建议您转移到mysqli,因为它比PDO更快、更容易,而且大多数api/语法与旧的mysql扩展是完全相同的

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

查看这里(在下面的滚动中)快速比较:PHP和MySQLi

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

编辑:看起来和你之前读过的链接一样,抱歉

#5


1  

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.

在构建我的ORM和抽象库时,我使用MySQLi和PDO来查看哪个性能更好。MySQLi的速度更快,但仅凭它还不足以做出选择。

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.

sqmyli /MySQL/SQLite或任何其他独立库在PDO上有一点是,它们返回结果中找到的行数,这通常有助于测试任何结果。同时,在PDO中,您可以获取结果并计数()——或者在查看结果数量之前运行一个计数查询。所以你必须适应以不同的方式处理这个问题。

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

哦,最后我选择PDO除以MySQLi。