• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

PHP/Mysql search/replace problem

Valter

Active member
#1
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.
 

Daniel Hood

Well-known member
#2
PHP:
$db->query(" UPDATE xf_post SET message = REPLACE(message, 'post: " . $results[post_id]} . "', 'post: " . $results[future_id] . "') ");
Try that.
 

Daniel Hood

Well-known member
#4
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?
 

Valter

Active member
#5
Thank You Daniel but I've just discovered that it was OK from the beginning. omg.png

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: