title: PHP - Regex for prepending table names within SQL
body: <p>I am looking for an unobtrusive way to find and replace table names based on their position in an SQL query.</p>
  
  <p>Example:</p>
  
  <pre><code>$query = 'SELECT t1.id, t1.name, t2.country FROM users AS t1, country AS t2 INNER JOIN another_table AS t3 ON t3.user_id = t1.id';
  </code></pre>
  
  <p>I essentially need to prepend client name abbreviations to table names and then have my CMS handle that change. So, going from 'users' to 'so_users' (If Stack Overflow was a client) but not have to add curly braces around all query table names like Drupal. An example is how WordPress will allow you on setup to prepend table names, but the way WordPress handles this issue is not ideal for my means.</p>
  
  <p>For my example I want the output of some method to be:</p>
  
  <pre><code>$query = 'SELECT t1.id, t1.name, t2.country FROM so_users AS t1, so_country AS t2 INNER JOIN so_another_table AS t3 ON t3.user_id = t1.id';
  </code></pre>
  
  <p>('so_' in prepended to table names)</p>
  
  <p>Thank you.</p>
  
  <p>Kris</p>