Skip to content

Commit

Permalink
Merge pull request #2208 from MGatner/db-get-prefix
Browse files Browse the repository at this point in the history
Add $db->getPrefix()
  • Loading branch information
lonnieezell authored Sep 11, 2019
2 parents afc7f1a + b10ea0a commit c925624
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
44 changes: 28 additions & 16 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
4 changes: 4 additions & 0 deletions user_guide_src/source/database/queries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
**********************
Expand Down

0 comments on commit c925624

Please sign in to comment.