summaryrefslogtreecommitdiff
path: root/it_dbi.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_dbi.class')
-rw-r--r--it_dbi.class33
1 files changed, 23 insertions, 10 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 585856e..95eb18a 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -116,21 +116,34 @@ function createclass($p)
if (!is_array($p))
$p = array('table' => $p);
- $classname = $p['classprefix'] . $p['table'];
+ # Make sure singleton exists
+ $dbi = $GLOBALS['it_dbi'] ? $GLOBALS['it_dbi'] : new it_dbi(array('table' => null) + $p);
+ $db = $dbi->_p['db'];
- if (substr($classname, 0, 4) != 'PMA_') # It is designed behaviour that an error is generated if this class already exists!
+ if (!isset($dbi->_tables[$db]))
{
- $code = "class $classname extends it_dbi
+ for ($res = $dbi->query('SHOW TABLES'); $row = mysql_fetch_row($res);)
+ $dbi->_tables[$db][] = $row[0];
+ }
+
+ if (in_array($p['table'], $dbi->_tables[$db])) # Do not generate classes for non-existant tables
+ {
+ $classname = $p['classprefix'] . $p['table'];
+
+ if (substr($classname, 0, 4) != 'PMA_') # It is designed behaviour that an error is generated if this class already exists!
{
- function $classname(\$query = null, \$p = array())
+ $code = "class $classname extends it_dbi
{
- \$p += " . var_export($p, true) . ";
- \$this->it_dbi(\$p, \$query);
- }
- }";
+ function $classname(\$query = null, \$p = array())
+ {
+ \$p += " . var_export($p, true) . ";
+ \$this->it_dbi(\$p, \$query);
+ }
+ }";
- debug("it_dbi::createclass('{$p['table']}'): creating class $classname", 5);
- eval($code);
+ debug("it_dbi::createclass('{$p['table']}'): creating class $classname", 5);
+ eval($code);
+ }
}
}