diff --git a/src/Medoo.php b/src/Medoo.php index c466bb19..b543c555 100644 --- a/src/Medoo.php +++ b/src/Medoo.php @@ -174,6 +174,13 @@ class Medoo */ public $errorInfo = null; + /** + * Table schema. + * + * @var string|null + */ + public $schema = null; + /** * Connect the database. * @@ -206,6 +213,10 @@ public function __construct(array $options) $this->prefix = $options['prefix']; } + if (isset($options['schema'])) { + $this->schema = $options['schema']; + } + if (isset($options['testMode']) && $options['testMode'] == true) { $this->testMode = true; return; @@ -710,7 +721,17 @@ public function quote(string $string): string */ public function tableQuote(string $table): string { + $schema = null; + if(strpos($table, '.') !== false && empty($this->schema)) { + [$schema, $table] = explode('.', $table); + } + if(!empty($this->schema)) { + $schema = $this->schema; + } if (preg_match('/^[\p{L}_][\p{L}\p{N}@$#\-_]*$/u', $table)) { + if($schema !== null) { + return $schema . '."' . $this->prefix . $table . '"'; + } return '"' . $this->prefix . $table . '"'; }