MySQL与PDO [英] MySQL versus PDO

查看:60
本文介绍了MySQL与PDO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PHP还是很陌生,并且已经使用标准的MySQL数据库调用建立了一个中型网站.但是,我最近了解了PDO,我希望从社区中了解是否值得从MySQL切换到PDO.为了安全起见,我一直使用mysql_real_escape_string.

I'm fairly new to PHP and have built a medium sized website using standard MySQL database calls. However, I have recently learned about PDO and I am hoping to find out from the community if it is worth switching from MySQL over to PDO. For security I have been using mysql_real_escape_string.

有关该网站的信息:
我正在混合使用INSERTSELECT调用.从SELECT调用返回的数据并不庞大(使用LIMIT返回的记录不超过30条). INSERT也不会很多.该站点目前尚未上线,因此现在进行更改很容易.

Info about the site:
I'm using a mix of INSERT and SELECT calls. The data returned from SELECT calls isn't massive (no more than 30 records returned by using LIMIT). There will also not be a whole lot of INSERTs. The site is currently not live and so making changes now is easy.

以您的专业意见,是否值得我花时间将站点从MySQL切换到PDO?还是和MySQL一样好?或者换句话说,如果有的话,现在切换到PDO的原因是什么?

In your professional opinions, is it worth my time to switch the site over to PDO from MySQL? Or is staying with MySQL just as good? Or in other words, what would be the reason, if any, to switch to PDO now?

推荐答案

与mysql_ *函数相比,PDO具有以下优点:

PDO has the following advantages over the mysql_* functions:

  • 它是跨数据库的,这意味着它是用于不同关系数据库的相同接口.
  • 它有助于防止SQL注入.
  • 它更加干净(使用面向对象的方法).

这个问题曾经被问过,您可能想看看答案:

This question has been asked before, you may want to take a look at the answers:

  • Moving from mysql to mysqli or pdo?
  • mysqli or PDO - what are the pros and cons?

如果您要开始一个新项目,我强烈建议您使用PDO或更高级别的库/ORM.如果您已经编写了很多没有它的代码,那可能不值得.

If you are starting a new project, I would strictly suggest using PDO or a higher-level library/ORM. If you already have a lot of code written without it, it may not be worth it.

这篇关于MySQL与PDO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆