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
.
关于网站的信息:
我混合使用了 INSERT
和 SELECT
调用.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 INSERT
s. 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:
- 从 mysql 迁移到 mysqli 或 pdo?
- mysqli 或 PDO - 优缺点是什么?
如果您要开始一个新项目,我会严格建议使用 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.
相关文章