cubrid_schema

(PECL CUBRID >= 8.3.0)

cubrid_schemaGet the requested schema information

Description

cubrid_schema(
    resource$conn_identifier,
    int$schema_type,
    string$class_name = ?,
    string$attr_name = ?
): array

The cubrid_schema() function is used to get the requested schema information from database. To get information about specific class, set the class_name, to get information about specific attribute (can be used only with CUBRID_SCH_ATTR_PRIVILEGE), set the attr_name.

The result of the cubrid_schema() function is returned as a two-dimensional array (column (associative array) * row (numeric array)). The following tables shows types of schema and the column structure of the result array to be returned based on the schema type.

Result Composition of Each Type
SchemaColumn NumberColumn NameValue
CUBRID_SCH_CLASS1NAME 
 2TYPE0:system class 1:vclass 2:class
CUBRID_SCH_VCLASS1NAME 
 2TYPE1:vclass
CUBRID_SCH_QUERY_SPEC1QUERY_SPEC 
CUBRID_SCH_ATTRIBUTE / CUBRID_SCH_CLASS_ATTRIBUTE1ATTR_NAME 
 2DOMAIN 
 3SCALE 
 4PRECISION 
 5INDEXED1:indexed
 6NOT NULL1:not null
 7SHARED1:shared
 8UNIQUE1:unique
 9DEFAULT 
 10ATTR_ORDERbase:1
 11CLASS_NAME 
 12SOURCE_CLASS 
 13IS_KEY1:key
CUBRID_SCH_METHOD / CUBRID_SCH_CLASS_METHOD1NAME 
 2RET_DOMAIN 
 3ARG_DOMAIN 
CUBRID_SCH_METHOD_FILE1METHOD_FILE 
CUBRID_SCH_SUPERCLASS / CUBRID_SCH_DIRECT_SUPER_CLASS / CUBRID_SCH_SUBCLASS1CLASS_NAME 
 2TYPE0:system class 1:vclass 2:class
CUBRID_SCH_CONSTRAINT1TYPE0:unique 1:index 2:reverse unique 3:reverse index
 2NAME 
 3ATTR_NAME 
 4NUM_PAGES 
 5NUM_KEYS 
 6PRIMARY_KEY1:primary key
 7KEY_ORDERbase:1
CUBRID_SCH_TRIGGER1NAME 
 2STATUS 
 3EVENT 
 4TARGET_CLASS 
 5TARGET_ATTR 
 6ACTION_TIME 
 7ACTION 
 8PRIORITY 
 9CONDITION_TIME 
 10CONDITION 
CUBRID_SCH_CLASS_PRIVILEGE / CUBRID_SCH_ATTR_PRIVILEGE1CLASS_NAME / ATTR_NAME 
 2PRIVILEGE 
 3GRANTABLE 
CUBRID_SCH_PRIMARY_KEY1CLASS_NAME 
 2ATTR_NAME 
 3KEY_SEQbase:1
 4KEY_NAME 
CUBRID_SCH_IMPORTED_KEYS / CUBRID_SCH_EXPORTED_KEYS / CUBRID_SCH_CROSS_REFERENCE1PKTABLE_NAME 
 2PKCOLUMN_NAME 
 3FKTABLE_NAMEbase:1
 4FKCOLUMN_NAME 
 5KEY_SEQbase:1
 6UPDATE_ACTION0:cascade 1:restrict 2:no action 3:set null
 7DELETE_ACTION0:cascade 1:restrict 2:no action 3:set null
 8FK_NAME 
 9PK_NAME 

Parameters

conn_identifier

Connection identifier.

schema_type

Schema data that you want to know.

class_name

Class you want to know the schema of.

attr_name

Attribute you want to know the schema of.

Return Values

Array containing the schema information, when process is successful, or false on failure.

Changelog

VersionDescription
8.3.1 Change return value: when process is unsuccessful, return false, not -1.

Examples

Example #1 cubrid_schema() example

<?php
$conn
= cubrid_connect("localhost", 33000, "demodb", "dba");

printf("\n--- Primary Key ---\n");
$pk = cubrid_schema($conn, CUBRID_SCH_PRIMARY_KEY, "game");
var_dump($pk);

printf("\n--- Foreign Keys ---\n");
$fk = cubrid_schema($conn, CUBRID_SCH_IMPORTED_KEYS, "game");
var_dump($fk);

printf("\n--- Column Attribute ---\n");
$attr = cubrid_schema($conn, CUBRID_SCH_ATTRIBUTE, "stadium", "area");
var_dump($attr);

cubrid_disconnect($conn);
?>

The above example will output:

--- Primary Key --- array(3) { [0]=> array(4) { ["CLASS_NAME"]=> string(4) "game" ["ATTR_NAME"]=> string(12) "athlete_code" ["KEY_SEQ"]=> string(1) "3" ["KEY_NAME"]=> string(41) "pk_game_host_year_event_code_athlete_code" } [1]=> array(4) { ["CLASS_NAME"]=> string(4) "game" ["ATTR_NAME"]=> string(10) "event_code" ["KEY_SEQ"]=> string(1) "2" ["KEY_NAME"]=> string(41) "pk_game_host_year_event_code_athlete_code" } [2]=> array(4) { ["CLASS_NAME"]=> string(4) "game" ["ATTR_NAME"]=> string(9) "host_year" ["KEY_SEQ"]=> string(1) "1" ["KEY_NAME"]=> string(41) "pk_game_host_year_event_code_athlete_code" } } --- Foreign Keys --- array(2) { [0]=> array(9) { ["PKTABLE_NAME"]=> string(7) "athlete" ["PKCOLUMN_NAME"]=> string(4) "code" ["FKTABLE_NAME"]=> string(4) "game" ["FKCOLUMN_NAME"]=> string(12) "athlete_code" ["KEY_SEQ"]=> string(1) "1" ["UPDATE_RULE"]=> string(1) "1" ["DELETE_RULE"]=> string(1) "1" ["FK_NAME"]=> string(20) "fk_game_athlete_code" ["PK_NAME"]=> string(15) "pk_athlete_code" } [1]=> array(9) { ["PKTABLE_NAME"]=> string(5) "event" ["PKCOLUMN_NAME"]=> string(4) "code" ["FKTABLE_NAME"]=> string(4) "game" ["FKCOLUMN_NAME"]=> string(10) "event_code" ["KEY_SEQ"]=> string(1) "1" ["UPDATE_RULE"]=> string(1) "1" ["DELETE_RULE"]=> string(1) "1" ["FK_NAME"]=> string(18) "fk_game_event_code" ["PK_NAME"]=> string(13) "pk_event_code" } } --- Column Attribute --- array(1) { [0]=> array(13) { ["ATTR_NAME"]=> string(4) "area" ["DOMAIN"]=> string(1) "7" ["SCALE"]=> string(1) "2" ["PRECISION"]=> string(2) "10" ["INDEXED"]=> string(1) "0" ["NON_NULL"]=> string(1) "0" ["SHARED"]=> string(1) "0" ["UNIQUE"]=> string(1) "0" ["DEFAULT"]=> NULL ["ATTR_ORDER"]=> string(1) "4" ["CLASS_NAME"]=> string(7) "stadium" ["SOURCE_CLASS"]=> string(7) "stadium" ["IS_KEY"]=> string(1) "0" } }
To Top