Re: Fetch table names from query
From: Álvaro G. Vicario <alvaroNOSPAMTHANKS_at_demogracia.com>
Date: Thu, 22 May 2008 11:24:08 +0200
Message-ID: <g13e2u$kh2$1@huron.algomas.org>
}
Date: Thu, 22 May 2008 11:24:08 +0200
Message-ID: <g13e2u$kh2$1@huron.algomas.org>
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 --Received on Thu May 22 2008 - 04:24:08 CDT