- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:dictionary:metaforeignkeys

# metaForeignKeys

##### Syntax

      mixed metaForeignKeys(
          string $tableName,
          optional string $owner=false,
          optional bool $upperCase=false,
          optional bool $associative=false
          )

## Description

The function `metaForeignKeys()` returns an array of the foreign keys associated with a specific table. If there are no foreign keys then the function returns false.

## Optional Parameters

### $owner

If specified, only returns foreign keys associated with a table owned by that name. Some drivers discard this parameter

### $upper

if specified, only matches the table with the uppercase name. This parameter is discarded by some drivers

### $associative

If specified, returns the result in associative mode. If ADODB_FETCH_MODE is already associative, then this parameter is discarded. Some drivers ignore this parameter.

## Return Value

The method returns an array of data:

- the main key represents the foreign table that the key associated with.
- The values of the key are either a key⇒value pair, the key being the column name of the source table and the value being the column name of the foreign table if the request is `associative`, or a numeric key with value being the same data represented as `local column` + '=' + `foreign column`.

## Usage

    /*
     * Connection to MySql Employees Sample database
    */
    $db->setFetchMode(ADODB_FETCH_NUM);

    $p = $db->metaForeignKeys('dept_emp');
    print_r($p);
    /*
     * prints
    Array
    (
        [employees] => Array
            (
                [0] => emp_no=emp_no
            )

        [departments] => Array
            (
                [0] => dept_no=dept_no
            )

    )
    */

### Same Code In Associative Mode

    $db->setFetchMode(ADODB_FETCH_ASSOC);

    $p = $db->metaForeignKeys('dept_emp');
    print_r($p);
    /*
     * prints
    Array
    (
        [employees] => Array
            (
                [emp_no]=>emp_no
            )

        [departments] => Array
            (
                [dept_no]=>dept_no
            )

    )
    */

v5/dictionary/metaforeignkeys.txt · Last modified: 2016/01/12 17:06 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top