I'm trying to change the url in various rows in multiple wp databases. So I wrote a piece of code that I think should work, but I'm getting an error with the global variable $wpdb.
The error states:
Catchable fatal error: Object of class wpdb could not be converted to string in /home/isaiahb/public_html/sexyafter30/wp-content/themes/twentyten/functions.php on line 107
Here's a snippet of the code:
function updateDBUrls(){
global $wpdb;
$my_dbs = array("bb_meta" => "meta_value", "bp_activity" => array("action", "content", "primary_link"), "posts" => "guid", "users" => "user_url");
foreach($my_dbs as $key => $value){
$rows = $wpdb->get_row("SELECT * FROM $wpdb->".$key." WHERE ".$value." REGEXP ' (.*)http://sociallyaffluent.com/21andolder(.*) ' ", ARRAY_A);
foreach ($rows as $singlerow){
$new_url = changeUrl($singlerow[$value]);
$wpdb->query(" UPDATE $wpdb->".$key." SET ".$value." = ".$new_url." WHERE ".$value." REGEXP ' (.*)http://sociallyaffluent.com/21andolder(.*) '");
} //end of inner foreach loop
} // end of beginning foreach loop
}// end function updateDBUrls
Apparently, this is the problem line (107):
$rows = $wpdb->get_row("SELECT * FROM $wpdb->".$key." WHERE ".$value." REGEXP ' (.*)http://sociallyaffluent.com/21andolder(.*) ' ", ARRAY_A);
Can anyone see where or if I'm misusing the $wpdb global variable?