Created
July 3, 2017 06:21
-
-
Save alikon/2d74ddc3fbf78a71ecddf4b51b18aff0 to your computer and use it in GitHub Desktop.
getTableForeignKeys($table)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getTableForeignKeys($table) | |
{ | |
$this->connect(); | |
// Get the details foreign keys information. | |
$query = $this->getQuery(true) | |
->select('tb1.CONSTRAINT_NAME, tb1.TABLE_NAME, tb1.COLUMN_NAME, ' . | |
'tb1.REFERENCED_TABLE_NAME, tb1.REFERENCED_COLUMN_NAME, tb2.MATCH_OPTION, ' . | |
'tb2.UPDATE_RULE, tb2.DELETE_RULE') | |
->from('information_schema.KEY_COLUMN_USAGE AS tb1') | |
->join('INNER', "information_schema.REFERENTIAL_CONSTRAINTS AS tb2 | |
ON tb1.CONSTRAINT_NAME = tb2.CONSTRAINT_NAME | |
AND tb1.TABLE_SCHEMA = tb2.CONSTRAINT_SCHEMA | |
AND tb1.TABLE_NAME = tb2.TABLE_NAME") | |
->where("tb1.TABLE_SCHEMA = " . $this->quote($this->options['database'])) | |
->where("tb1.TABLE_NAME = " . $this->quote($table)); | |
$this->setQuery($query); | |
try | |
{ | |
$keys = $this->loadObjectList(); | |
} | |
catch (Exception $e) | |
{ | |
JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database'); | |
throw new JDatabaseExceptionExecuting($query, $this->errorMsg, $this->errorNum); | |
} | |
return $keys; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment