public function getTableForeignKeys( $table )
    {
        $query = 'SELECT CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME,
                  REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
                  FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ?
                  AND TABLE_NAME = ? AND REFERENCED_COLUMN_NAME IS NOT NULL;';

        $params = [ $this->name, $table ];

        $statement = $this->database->prepare( $query );
        $statement->execute( $params );

        $results = $statement->fetchAll();

        $keys = [ ];

        if ( !empty( $results ) )
        {
            foreach ( $results as $result )
            {
                $record                          = [ ];
                $record[ 'database' ]            = $result[ 'CONSTRAINT_SCHEMA' ];
                $record[ 'key_name' ]            = $result[ 'CONSTRAINT_NAME' ];
                $record[ 'table' ]               = $result[ 'TABLE_NAME' ];
                $record[ 'column' ]              = $result[ 'COLUMN_NAME' ];
                $record[ 'referenced_database' ] = $result[ 'REFERENCED_TABLE_SCHEMA' ];
                $record[ 'referenced_table' ]    = $result[ 'REFERENCED_TABLE_NAME' ];
                $record[ 'referenced_column' ]   = $result[ 'REFERENCED_COLUMN_NAME' ];

                $keys[ ] = $record;
            }
        }

        return $keys;
    }
public function getTableForeignKeys( $table )
    {
        $query = 'SELECT CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME,
                  REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
                  FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ?
                  AND TABLE_NAME = ? AND REFERENCED_COLUMN_NAME IS NOT NULL;';

        $params = [ $this->name, $table ];

        $statement = $this->database->prepare( $query );
        $statement->execute( $params );

        $results = $statement->fetchAll();

        $keys = [ ];

        if ( !empty( $results ) )
        {
            foreach ( $results as $result )
            {
                $record                          = [ ];
                $record[ 'database' ]            = $result[ 'CONSTRAINT_SCHEMA' ];
                $record[ 'key_name' ]            = $result[ 'CONSTRAINT_NAME' ];
                $record[ 'table' ]               = $result[ 'TABLE_NAME' ];
                $record[ 'column' ]              = $result[ 'COLUMN_NAME' ];
                $record[ 'referenced_database' ] = $result[ 'REFERENCED_TABLE_SCHEMA' ];
                $record[ 'referenced_table' ]    = $result[ 'REFERENCED_TABLE_NAME' ];
                $record[ 'referenced_column' ]   = $result[ 'REFERENCED_COLUMN_NAME' ];

                $keys[ ] = $record;
            }
        }

        return $keys;
    }
public function getTableForeignKeys ( $ table ) { $ query = 'SELECT CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME,
                  REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
                  FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ?
                  AND TABLE_NAME = ? AND REFERENCED_COLUMN_NAME IS NOT NULL;' ; $ params = [ $ this -> name , $ table ] ; $ statement = $ this -> database -> prepare ( $ query ) ; $ statement -> execute ( $ params ) ; $ results = $ statement -> fetchAll ( ) ; $ keys = [ ] ; if ( ! empty ( $ results ) ) { foreach ( $ results as $ result ) { $ record = [ ] ; $ record [ 'database' ] = $ result [ 'CONSTRAINT_SCHEMA' ] ; $ record [ 'key_name' ] = $ result [ 'CONSTRAINT_NAME' ] ; $ record [ 'table' ] = $ result [ 'TABLE_NAME' ] ; $ record [ 'column' ] = $ result [ 'COLUMN_NAME' ] ; $ record [ 'referenced_database' ] = $ result [ 'REFERENCED_TABLE_SCHEMA' ] ; $ record [ 'referenced_table' ] = $ result [ 'REFERENCED_TABLE_NAME' ] ; $ record [ 'referenced_column' ] = $ result [ 'REFERENCED_COLUMN_NAME' ] ; $ keys [ ] = $ record ; } } return $ keys ; }
Returns a list of foreign keys for a table.

@param string $table table name

@return array list of foreign keys
Returns a list of foreign keys for a table .