MySQL 与 PDO

MySQL versus PDO(MySQL 与 PDO)
本文介绍了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:

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)