PHP/Mysql search/replace problem

Valter

Active member
Can anyone tell me what's wrong with this query? When executed nothing is found/replaced.
PHP:
  foreach($query AS $rowName => $results)
   {
     $db->query(" UPDATE xf_post SET message = REPLACE(message, 'post: {$results[post_id]}', 'post: {$results[future_id]}') ");
   }

This is part of our internal script to fix some quotes on the forums.

When manually executed via myAdmin it works perfectly.
Example: UPDATE xf_post SET message = REPLACE(message, 'post: 317', 'post: 126');
But with variables in PHP it won't find/replace anything.

Thanks in advance.
 
PHP:
$db->query(" UPDATE xf_post SET message = REPLACE(message, 'post: " . $results[post_id]} . "', 'post: " . $results[future_id] . "') ");

Try that.
 
Define "doesn't work" please. Does it error, does it replace incorrectly, does it execute but not replace?

Add
PHP:
 Zend_Debug::dump ($results)
before the query. Maybe it doesn't hold the variables you're hoping for?
 
Thank You Daniel but I've just discovered that it was OK from the beginning. omg.webp

The problem was code position in the script. It searched for correct strings and tried to replace it but these simply doesn't exist atm LOL.
 
Last edited:
Back
Top Bottom