Drupal 6 db_query 文件表
作为从 Windows 服务器迁移到 Linux 服务器的一部分,我必须清理大量文件名。
我的问题是,当我执行:
db_query("UPDATE {files} SET filename = '%s' AND filepath = '%s' WHERE fid = %d", $file->filename, $file-> ;filepath, $file->fid);
然后选择 $file->fid 的内容,文件名字段的值为“0”
如果我在查询之前和之后将查询转储为文本执行后,文件名字段包含我指定的文件名,因为文件路径正确存储在其中。
As part of moving from a windows server to a linux server I have to clean up a large number of filenames.
My Problem is that when I execute:
db_query("UPDATE {files} SET filename = '%s' AND filepath = '%s' WHERE fid = %d", $file->filename, $file->filepath, $file->fid);
and afterwards select the content for $file->fid the filename field has the value of "0"
If I dump the query as text both before and after it's being executed the filename field contains the filename I have specified where as the filepath is being stored correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该死!将 AND 放入更新查询中不会产生预期的结果...MySQL 允许这样做,但这不是正确的方法:)
DAMN! putting an AND into an update query will not produce the expected result... MySQL allows this but it's not the way to go :)
使用逗号代替 AND。
可能还想考虑使用 drupal_write_record() 而不是 db_query。如果您添加要检查的键的第三个参数,drupal_write_record 将自动更新预先存在的行。在您的情况下,您可以使用文件 ID。
Use a comma instead of AND.
Might also want to look into using drupal_write_record() instead of db_query. drupal_write_record will automatically update a pre-existing row if you add the 3rd parameter for a key to check. In your case, you could use the file id.