dongsimang4036 2014-01-24 20:35 采纳率: 100%
浏览 63
已采纳

预准备语句如何在SQL级别上运行?

Until now, I hapily lived with the escaping functions and the paradigm that clients communicates with the server using just sql commands:

select * from table where name = 'O\'Hara';

In the case of PDO, where you just create some template and feed it with different data, this paradigm is very likely broken. If not, the PDO would have to just call the escaping function itself, and there would really be no reason to use it (wouldn't be any different from escaping it yourself).

So, if the SQL communication paradigm between client and server is broken, how does it work? Are the queries no more send as SQL commands? Is it some extension of MySQL protocol? Is the MySQL protocol far more rich than just SQL conversation? Does it work in general, e.g. using remote server? Are there any limits for this feature compared to bare SQL commanding?

I have tried going through the mysql docs but haven't found anything relevant.

  • 写回答

1条回答 默认 最新

  • dongmao4486 2014-01-24 20:41
    关注

    Therory:

    Prepared statements are indeed a feature on protocol level, meaning the client sends the query template first and the parameters in second request. Also the client can send multiple data requests for the same - already prepared - query. (That's why the name)

    Reality:

    The PDO code is written in a way, that it not utilizes the protocol feature, it really just escapes the values and replaces the placeholders in the statement with that escaped values and then sends a regular SQL query to the server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大