如何在 PHP UPDATE 查询中引用 Imagick 对象?

发布于 2024-12-13 18:47:10 字数 197 浏览 4 评论 0原文

这个查询有什么问题?

我正在尝试将 ImageMagick 对象写回数据库(PostgreSQL bytea 字段)。 这是 PHP 代码 - 使用 Imagick 函数。

$query = "UPDATE table SET destcol = ".$im." WHERE key = " .$args[0];

What is wrong with this query?

Am trying to write an ImageMagick object back into a database (a PostgreSQL bytea field).
This is PHP code - using the Imagick functions.

$query = "UPDATE table SET destcol = ".$im." WHERE key = " .$args[0];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-12-20 18:47:10

如果 $im 是来自执行操作,那么

$im = new Imagick();

您的查询将会失败。您不能像这样将 PHP 对象插入到数据库中。至少,您必须执行类似的操作

$im = new Imagick();
$serialized = serialize($im);
$safe_serialized = mysql_real_escape_string($serialized);

$sql = "INSERT ... destcol='$safe_serialized' ...";

还要注意,这很可能会失败 - 如果对象在内部保存打开的文件,那么一旦将对象从数据库中拉出并取消序列化()',这些文件句柄几乎肯定会无效d.

为什么需要以这种方式保存一个 imagick 对象?首先实例化它的成本并不高。

If that $im is from doing

$im = new Imagick();

your query will fail. You cannot insert a PHP object into a database like that. At bare mininum, you must do something like

$im = new Imagick();
$serialized = serialize($im);
$safe_serialized = mysql_real_escape_string($serialized);

$sql = "INSERT ... destcol='$safe_serialized' ...";

Also note that this will most likely fail - if the object is holding open files internally, those file handles will almost certainly not be valid once the object is pulled out of the database and unserialize()'d.

Why do you need to preserve an imagick object in this fashion? The cost of instantiating it in the first place is not exactly high.

习惯成性 2024-12-20 18:47:10

我猜测您正在更新字符串列而不引用它们。

$query = "UPDATE table SET destcol = '".$im."' WHERE key = '" .$args[0]. "'";

I'm going to guess that you're updating string columns without quoting them.;

$query = "UPDATE table SET destcol = '".$im."' WHERE key = '" .$args[0]. "'";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文