开发者

Drupal 6 db_query files table

开发者 https://www.devze.com 2023-02-17 22:57 出处:网络
As part of moving from a windows server to a linux server I have to clean up a large number of filenames.

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 =开发者_StackOverflow社区 '%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.


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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消