”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 如何使用PHP将斑点(图像)正确插入MySQL?

如何使用PHP将斑点(图像)正确插入MySQL?

发布于2025-06-14
浏览:242

How to Properly Insert Blobs (Images) into MySQL using PHP?

essue

VALUES('$this->image_id','file_get_contents($tmp_image)')";

This code builds a string in PHP, but the function call file_get_contents($tmp_image) is not evaluated before the string is created.因此,未插入实际的二进制数据。

解决方案1 ​​

要解决这个问题,您需要明确地将函数的结果与函数呼叫:

VALUES('$this->image_id','" . file_get_contents($tmp_image) . "')";


Solution 2

Additionally, ensure that any characters in the binary data that might interfere with the query被逃脱了:

最新教程 更多>

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3