From 32fd206ba8aa2f734e3f21232a1a2dc8248a1be3 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 10 Sep 2019 09:26:34 -0400 Subject: [PATCH 1/2] Add getter for DBPrefix --- system/Database/BaseConnection.php | 44 +++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 8bcbac95dc28..6ff838c94f56 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -514,6 +514,34 @@ public function getDatabase(): string //-------------------------------------------------------------------- + /** + * Set DB Prefix + * + * Set's the DB Prefix to something new without needing to reconnect + * + * @param string $prefix The prefix + * + * @return string + */ + public function setPrefix(string $prefix = ''): string + { + return $this->DBPrefix = $prefix; + } + + //-------------------------------------------------------------------- + + /** + * Returns the database prefix. + * + * @return string + */ + public function getPrefix(): string + { + return $this->DBPrefix; + } + + //-------------------------------------------------------------------- + /** * Returns the last error encountered by this connection. * @@ -1329,22 +1357,6 @@ public function prefixTable(string $table = ''): string //-------------------------------------------------------------------- - /** - * Set DB Prefix - * - * Set's the DB Prefix to something new without needing to reconnect - * - * @param string $prefix The prefix - * - * @return string - */ - public function setPrefix(string $prefix = ''): string - { - return $this->DBPrefix = $prefix; - } - - //-------------------------------------------------------------------- - /** * Returns the total number of rows affected by this query. * From b10ea0ad8c33dae5bdc73cd727026ec46c9ef39a Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 10 Sep 2019 09:28:55 -0400 Subject: [PATCH 2/2] Add getPrefix to User Guide --- user_guide_src/source/database/queries.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guide_src/source/database/queries.rst b/user_guide_src/source/database/queries.rst index 63b60724e377..cb6588d1a509 100644 --- a/user_guide_src/source/database/queries.rst +++ b/user_guide_src/source/database/queries.rst @@ -72,6 +72,10 @@ without needing to create a new connection you can use this method:: $db->setPrefix('newprefix'); $db->prefixTable('tablename'); // outputs newprefix_tablename +You can get the current prefix any time with this method:: + + $DBPrefix = $db->getPrefix(); + ********************** Protecting identifiers **********************