1. 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

Discussion in 'XenForo Development Discussions' started by Valter, Jul 30, 2014.

  1. Valter

    Valter Active Member

    Can anyone tell me what's wrong with this query? When executed nothing is found/replaced.
      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.
  2. Daniel Hood

    Daniel Hood Well-Known Member

    $db->query(" UPDATE xf_post SET message = REPLACE(message, 'post: " $results[post_id]} . "', 'post: " $results[future_id] . "') ");
    Try that.
  3. Valter

    Valter Active Member

    Thanks, but it doesn't work either.

    Yes, I removed extra "}" after "$results[post_id]".
  4. Daniel Hood

    Daniel Hood Well-Known Member

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

     Zend_Debug::dump ($results)
    before the query. Maybe it doesn't hold the variables you're hoping for?
    Valter likes this.
  5. Valter

    Valter Active Member

    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: Aug 1, 2014
    Daniel Hood likes this.

Share This Page