Page MenuHomeDevCentral

D2511.id6333.diff
No OneTemporary

D2511.id6333.diff

diff --git a/src/DatabaseEngine.php b/src/DatabaseEngine.php
--- a/src/DatabaseEngine.php
+++ b/src/DatabaseEngine.php
@@ -30,6 +30,13 @@
protected abstract function getExceptionContext (): array;
+ /**
+ * Determines if the specified table or view exists.
+ */
+ public abstract function isExistingTable (
+ string $database, string $table
+ ) : bool;
+
///
/// Engine mechanics
///
diff --git a/src/Engines/MySQLiEngine.php b/src/Engines/MySQLiEngine.php
--- a/src/Engines/MySQLiEngine.php
+++ b/src/Engines/MySQLiEngine.php
@@ -16,6 +16,8 @@
class MySQLiEngine extends DatabaseEngine {
+ use WithMySQL;
+
/**
* The connection identifier
*/
diff --git a/src/Engines/WithMySQL.php b/src/Engines/WithMySQL.php
new file mode 100644
--- /dev/null
+++ b/src/Engines/WithMySQL.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Keruald\Database\Engines;
+
+trait WithMySQL {
+
+ public function isExistingTable (string $database, string $table) : bool {
+ $escapedTable = $this->escape($table);
+ $sql = "SHOW TABLE STATUS
+ FROM `$database`
+ WHERE Name = '$escapedTable'";
+
+ return $this->queryScalar($sql) === $table;
+ }
+
+ public function isView (string $database, string $view) : bool {
+ $escapedView = $this->escape($view);
+ $escapedDatabase = $this->escape($database);
+
+ $sql = <<<EOF
+SELECT TABLE_TYPE
+FROM information_schema.tables
+WHERE TABLE_SCHEMA = "$escapedDatabase" AND TABLE_NAME = "$escapedView"
+EOF;
+
+ return $this->queryScalar($sql) === "VIEW";
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 18:24 (18 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2258652
Default Alt Text
D2511.id6333.diff (1 KB)

Event Timeline