title: Extract table names from any select query using PHP
body: <p>I tried to get the all the table names from a query using PHP, using this function I got all my conditions except JOINS with multiple tables, please help me to extract JOIN query also, using this same function.</p>
  
  <pre><code>private function get_tables($query)
  {
      $arr        =   explode("FROM", $query);
      $second     =   $arr[1];
  
      if($second==""){
          $arr    =   explode("from", $query);
          $second =   $arr[1];
      }
  
      $consts =   array('where','order', 'group', 'limit');
      $check=1;
  
      for($i=0;$i&lt;count($consts); $i++)
      {
        if((stristr($second,$consts[$i])  !=  '')&amp;&amp;($check==1))
        {
            $where    =   explode($consts[$i],$second);
            if($check == 1)
            {
                $check=2;
                $tables= $where[0];
            }
        }
      }
      if($check == 1)
      {
        $tables= $arr[1]; 
      }
      $tab_arr    =   explode(',',$tables);
      $name_arr   =   array();
  
      foreach($tab_arr as $name)
      {
        if($name != '')
        { 
            $name =   trim($name);
            $narr =   explode(' ',$name);     
            $name_arr[]   =   $narr[0];
        }
  
      }
      $name_arr   =   array_unique($name_arr);
      return $name_arr;
  }
  </code></pre>