View Single Post

   
  #6 (permalink)  
Old 05-24-2008, 07:10 AM
=?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=
 
Posts: n/a
Default Re: Fetch table names from query

Shakespeare escribió:
> You could make life a little bit simpler by storing relevant tablenames in a
> table (!) and scanning your queries and cache for these names. Not 100%
> accurate, but it might help a little.


Actually, that's exactly my current PHP-side solution ;-)

<?php

$regex_tables = implode('|', $tables); // $tables contains table names
$regex = '/\W(FROM|JOIN)\s+(' . $regex_tables . ')(?:\W|$)/i';
preg_match_all($regex, $sql, $matches);

if(isset($matches[2]) && count($matches[2])>0){
$tables = array_unique($matches[2]);
sort($tables);
}

?>



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Reply With Quote