metaForeignKeys

Syntax
  mixed metaForeignKeys(
      string $tableName,
      optional string $owner='',
      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, the table and columns are returned in uppercase. Default is lowercase.

$associative

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

Return Value

The method returns an array of data:

Explanation

A table child_table has a foreign key that references parent_table. child_table has 2 columns parent_id and parent_type. These 2 columns reference corresponding columns in parent_table, id and type. metaForignKeys() presents this data in the following way:

Associative Mode

[
    ['parent_table'] [
        ['parent_id'] => 'id',
        ['parent_type'] => 'type'
    ]
]

Numeric Mode

[
    [0] => [
        [0] => 'parent_id=id',
        [1] => 'parent_type=type'
    ]
]

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
        )
 
)
*/