Commit 9bbea7a2 authored by Alexander Butenko's avatar Alexander Butenko

Added tableExists

parent bc6ddffc
......@@ -1457,5 +1457,25 @@ class MysqliDb
return __CLASS__ . "->" . $caller["function"] . "() >> file \"" .
str_replace ($this->traceStripPrefix, '', $caller["file"] ) . "\" line #" . $caller["line"] . " " ;
}
/**
* Method to check if needed table is created
*
* @param array $tables Table name or an Array of table names to check
*
* @returns boolean True if table exists
*/
public function tableExists ($tables) {
$tables = !is_array ($tables) ? Array ($tables) : $tables;
$count = count ($tables);
if ($count == 0)
return false;
array_walk ($tables, function (&$value, $key) { $value = self::$prefix . $value; });
$this->where ('table_schema', $this->db);
$this->where ('table_name', $tables, 'IN');
$this->get ('information_schema.tables', $count);
return $this->count == $count;
}
} // END class
?>
......@@ -525,19 +525,24 @@ if($db->has("users")) {
}
```
### Helper commands
Reconnect in case mysql connection died
Reconnect in case mysql connection died:
```php
if (!$db->ping())
$db->connect()
```
Get last executed SQL query.
Get last executed SQL query:
Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables.
```php
$db->get('users');
echo "Last executed query was ". $db->getLastQuery();
```
Check if table exists:
```php
if ($db->tableExists ('users'))
echo "hooray";
```
### Transaction helpers
Please keep in mind that transactions are working on innoDB tables.
Rollback transaction if insert fails:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment