[wp-hackers] Best functions in WP for bulk MySQL processing?

Dion Hulse (dd32) wordpress at dd32.id.au
Sun Mar 14 06:20:06 UTC 2010


On Sun, 14 Mar 2010 16:33:28 +1200, Mike Schinkel  
<mikeschinkel at newclarity.net> wrote:

> Hey all,
>
> I'm writing a tool to help automatically move from one domain to  
> another.  To do this I need to process through all post_content and  
> post_excerpt fields and change any image locations that reference the  
> old domain with the new domain (there are other things I need to do but  
> I'm taking baby steps first.)
>
> As far as I can tell WordPress' database functions like $wpdb->query()  
> load all posts into memory which won't work for a really large database;  
> it would exhaust memory.  While I can easily write SQL code using the  
> mysql_* functions I'd prefer to do it using WordPress functions.  Are  
> there functions available to use for bulk processing, one I've just not  
> found yet?

You might like to have a look at the Search and Replace plugin for  
inspiration.

As for reducing memory consumption, You might be best doing replacements  
at the SQL layer using REPLACE():  
http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_replace

-- 
Dion Hulse / dd32
Contact:
  e: contact at dd32.id.au
  Web: http://dd32.id.au/


More information about the wp-hackers mailing list