Book/uodbc-Phpdoc专题

ODBC (Unified)

目录

In addition to normal ODBC support, the Unified ODBC functions in PHP allow you to access several databases that have borrowed the semantics of the ODBC API to implement their own API. Instead of maintaining multiple database drivers that were all nearly identical, these drivers have been unified into a single set of ODBC functions.

The following databases are supported by the Unified ODBC functions: » Adabas D, » IBM DB2, » iODBC, » Solid, and » Sybase SQL Anywhere.

Note:

With the exception of iODBC, there is no ODBC involved when connecting to the above databases. The functions that you use to speak natively to them just happen to share the same names and syntax as the ODBC functions. However, building PHP with iODBC support enables you to use any ODBC-compliant drivers with your PHP applications. More information on iODBC, is available at » www.iodbc.org with the alternative unixODBC available at » www.unixodbc.org.

安装/配置

目录

需求

To access any of the supported databases you need to have the required libraries installed.

安装

--with-adabas[=DIR]
Include Adabas D support. DIR is the Adabas base install directory, defaults to /usr/local.

--with-sapdb[=DIR]
Include SAP DB support. DIR is SAP DB base install directory, defaults to /usr/local.

--with-solid[=DIR]
Include Solid support. DIR is the Solid base install directory, defaults to /usr/local/solid.

--with-ibm-db2[=DIR]
Include IBM DB2 support. DIR is the DB2 base install directory, defaults to /home/db2inst1/sqllib.

--with-empress[=DIR]
Include Empress support. DIR is the Empress base install directory, defaults to $EMPRESSPATH. This option only supports Empress Version 8.60 and above.

--with-empress-bcs[=DIR]
Include "Empress Local Access" support. DIR is the Empress base install directory, defaults to $EMPRESSPATH. This option only supports Empress Version 8.60 and above.

--with-birdstep[=DIR]
Include Birdstep support. DIR is the Birdstep base install directory, defaults to /usr/local/birdstep.

--with-custom-odbc[=DIR]
Include a user defined ODBC support. The DIR is ODBC install base directory, which defaults to /usr/local. Make sure to define CUSTOM_ODBC_LIBS and have some odbc.h in your include dirs. E.g., you should define following for Sybase SQL Anywhere 5.5.00 on QNX, prior to run configure script:

   CPPFLAGS="-DODBC_QNX -DSQLANY_BUG"
   LDFLAGS=-lunix
   CUSTOM_ODBC_LIBS="-ldblib -lodbc".

--with-iodbc[=DIR]
Include iODBC support. DIR is the iODBC base install directory, defaults to /usr/local.

--with-esoob[=DIR]
Include Easysoft OOB support. DIR is the OOB base install directory, defaults to /usr/local/easysoft/oob/client.

--with-unixODBC[=DIR]
Include unixODBC support. DIR is the unixODBC base install directory, defaults to /usr/local.

--with-openlink[=DIR]
Include OpenLink ODBC support. DIR is the OpenLink base install directory, defaults to /usr/local. This is the same as iODBC.

--with-dbmaker[=DIR]
Include DBMaker support. DIR is the DBMaker base install directory, defaults to where the latest version of DBMaker is installed (such as /home/dbmaker/3.6).

PHP 的 Windows 版本已内建对此扩展的支持。不需要载入额外的扩展来使用这些函数。

As of PHP 7.0.0, however, Windows users must enable php_odbc.dll in order to use this extension.

运行时配置

这些函数的行为受 php.ini 中的设置影响。

名字 默认 可修改范围 更新日志
odbc.default_db * NULL PHP_INI_ALL  
odbc.default_user * NULL PHP_INI_ALL  
odbc.default_pw * NULL PHP_INI_ALL  
odbc.allow_persistent "1" PHP_INI_SYSTEM  
odbc.check_persistent "1" PHP_INI_SYSTEM  
odbc.max_persistent "-1" PHP_INI_SYSTEM  
odbc.max_links "-1" PHP_INI_SYSTEM  
odbc.defaultlrl "4096" PHP_INI_ALL  
odbc.defaultbinmode "1" PHP_INI_ALL  
odbc.default_cursortype "3" PHP_INI_ALL Available as of PHP 5.3.0

Note: Entries marked with * are not implemented yet.

有关 PHP_INI_* 样式的更多详情与定义,见 配置可被设定范围

这是配置指令的简短说明。

odbc.default_db string
ODBC data source to use if none is specified in <span class="function">odbc_connect or <span class="function">odbc_pconnect.

odbc.default_user string
User name to use if none is specified in <span class="function">odbc_connect or <span class="function">odbc_pconnect.

odbc.default_pw string
Password to use if none is specified in <span class="function">odbc_connect or <span class="function">odbc_pconnect.

odbc.allow_persistent bool
Whether to allow persistent ODBC connections.

odbc.check_persistent bool
Check that a connection is still valid before reuse.

odbc.max_persistent int
The maximum number of persistent ODBC connections per process.

odbc.max_links int
The maximum number of ODBC connections per process, including persistent connections.

odbc.defaultlrl int
Handling of LONG fields. Specifies the number of bytes returned to variables. See odbc_longreadlen for details.

当使用 int 时, 其值以字节来衡量。还可以使用在FAQ中描述的速记符。

odbc.defaultbinmode int
Handling of binary data. See odbc_binmode for details.

odbc.default_cursortype int
Controls the ODBC cursor model. Possible values are SQL_CURSOR_FORWARD_ONLY, SQL_CURSOR_KEYSET_DRIVEN, SQL_CURSOR_DYNAMIC and SQL_CURSOR_STATIC (default).

资源类型

This extension defines two resource types: an ODBC connection identifier and an ODBC result identifier.

预定义常量

下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。

ODBC_TYPE (int)

ODBC_BINMODE_PASSTHRU (int)

ODBC_BINMODE_RETURN (int)

ODBC_BINMODE_CONVERT (int)

SQL_ODBC_CURSORS (int)

SQL_CUR_USE_DRIVER (int)

SQL_CUR_USE_IF_NEEDED (int)

SQL_CUR_USE_ODBC (int)

SQL_CONCURRENCY (int)

SQL_CONCUR_READ_ONLY (int)

SQL_CONCUR_LOCK (int)

SQL_CONCUR_ROWVER (int)

SQL_CONCUR_VALUES (int)

SQL_CURSOR_TYPE (int)

SQL_CURSOR_FORWARD_ONLY (int)

SQL_CURSOR_KEYSET_DRIVEN (int)

SQL_CURSOR_DYNAMIC (int)

SQL_CURSOR_STATIC (int)

SQL_KEYSET_SIZE (int)

SQL_CHAR (int)

SQL_VARCHAR (int)

SQL_LONGVARCHAR (int)

SQL_DECIMAL (int)

SQL_NUMERIC (int)

SQL_BIT (int)

SQL_TINYINT (int)

SQL_SMALLINT (int)

SQL_INTEGER (int)

SQL_BIGINT (int)

SQL_REAL (int)

SQL_FLOAT (int)

SQL_DOUBLE (int)

SQL_BINARY (int)

SQL_VARBINARY (int)

SQL_LONGVARBINARY (int)

SQL_DATE (int)

SQL_TIME (int)

SQL_TIMESTAMP (int)

SQL_TYPE_DATE (int)

SQL_TYPE_TIME (int)

SQL_TYPE_TIMESTAMP (int)

SQL_BEST_ROWID (int)

SQL_ROWVER (int)

SQL_SCOPE_CURROW (int)

SQL_SCOPE_TRANSACTION (int)

SQL_SCOPE_SESSION (int)

SQL_NO_NULLS (int)

SQL_NULLABLE (int)

SQL_INDEX_UNIQUE (int)

SQL_INDEX_ALL (int)

SQL_ENSURE (int)

SQL_QUICK (int)

odbc_autocommit

Toggle autocommit behaviour

说明

int<span class="type">bool <span class="methodname">odbc_autocommit ( <span class="methodparam">resource $odbc [, bool $enable = false ] )

Toggles autocommit behaviour.

By default, auto-commit is on for a connection. Disabling auto-commit is equivalent with starting a transaction.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

enable
If enable is true, auto-commit is enabled, if it is false auto-commit is disabled.

返回值

Without the enable parameter, this function returns auto-commit status for odbc. Non-zero is returned if auto-commit is on, 0 if it is off, or false if an error occurs.

If enable is set, this function returns true on success and false on failure.

参见

  • odbc_commit
  • odbc_rollback

odbc_binmode

Handling of binary column data

说明

bool <span class="methodname">odbc_binmode ( <span class="methodparam">resource $statement , <span class="type">int $mode )

Controls handling of binary column data. ODBC SQL types affected are BINARY, VARBINARY, and LONGVARBINARY. The default mode can be set using the uodbc.defaultbinmode php.ini directive.

When binary SQL data is converted to character C data (ODBC_BINMODE_CONVERT), each byte (8 bits) of source data is represented as two ASCII characters. These characters are the ASCII character representation of the number in its hexadecimal form. For example, a binary 00000001 is converted to "01" and a binary 11111111 is converted to "FF".

While the handling of BINARY and VARBINARY columns only depend on the binmode, the handling of LONGVARBINARY columns also depends on the longreadlen as well:

binmode longreadlen result
ODBC_BINMODE_PASSTHRU 0 passthru
ODBC_BINMODE_RETURN 0 passthru
ODBC_BINMODE_CONVERT 0 passthru
ODBC_BINMODE_PASSTHRU >0 passthru
ODBC_BINMODE_RETURN >0 return as is
ODBC_BINMODE_CONVERT >0 return as char

If odbc_fetch_into is used, passthru means that an empty string is returned for these columns. If <span class="function">odbc_result is used, passthru means that the data are sent directly to the client (i.e. printed).

参数

statement
The result identifier.

If statement is 0, the settings apply as default for new results.

mode
Possible values for mode are:

  • ODBC_BINMODE_PASSTHRU: Passthru BINARY data
  • ODBC_BINMODE_RETURN: Return as is
  • ODBC_BINMODE_CONVERT: Convert to char and return

Note: Handling of binary long columns is also affected by odbc_longreadlen.

返回值

成功时返回 true, 或者在失败时返回 false

odbc_close_all

Close all ODBC connections

说明

void <span class="methodname">odbc_close_all ( <span class="methodparam">void )

odbc_close_all will close down all connections to database server(s).

参数

此函数没有参数。

返回值

没有返回值。

注释

Note:

This function will fail if there are open transactions on a connection. This connection will remain open in this case.

odbc_close

Close an ODBC connection

说明

void <span class="methodname">odbc_close ( <span class="type">resource $odbc )

Closes down the connection to the database server.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

返回值

没有返回值。

注释

Note:

This function will fail if there are open transactions on this connection. The connection will remain open in this case.

odbc_columnprivileges

Lists columns and associated privileges for the given table

说明

resource<span class="type">false <span class="methodname">odbc_columnprivileges ( <span class="methodparam">resource $odbc , <span class="type">stringnull $catalog , <span class="type">string $schema , <span class="methodparam">string $table , string $column )

Lists columns and associated privileges for the given table.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance). 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

table
The table name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

column
The column name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

返回值

Returns an ODBC result identifier 或者在失败时返回 false. This result identifier can be used to fetch a list of columns and associated privileges.

The result set has the following columns:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • COLUMN_NAME
  • GRANTOR
  • GRANTEE
  • PRIVILEGE
  • IS_GRANTABLE

Drivers can report additional columns.

The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME and PRIVILEGE.

范例

示例 #1 List Privileges for a Column

<?php
$conn = odbc_connect($dsn, $user, $pass);
$privileges = odbc_columnprivileges($conn, 'TutorialDB', 'dbo', 'test', 'id');
while (($row = odbc_fetch_array($privileges))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [TABLE_CAT] => TutorialDB
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => test
    [COLUMN_NAME] => id
    [GRANTOR] => dbo
    [GRANTEE] => dbo
    [PRIVILEGE] => INSERT
    [IS_GRANTABLE] => YES
)

odbc_columns

Lists the column names in specified tables

说明

resource<span class="type">false <span class="methodname">odbc_columns ( <span class="methodparam">resource $odbc [, <span class="type">stringnull $catalog = null [, <span class="type">stringnull $schema = null [, <span class="methodparam"><span class="type">stringnull $table = null [, <span class="methodparam"><span class="type">stringnull $column = null ]]]] )

Lists all columns in the requested range.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance). 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

table
The table name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

column
The column name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

返回值

Returns an ODBC result identifier 或者在失败时返回 false.

The result set has the following columns:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • COLUMN_NAME
  • DATA_TYPE
  • TYPE_NAME
  • COLUMN_SIZE
  • BUFFER_LENGTH
  • DECIMAL_DIGITS
  • NUM_PREC_RADIX
  • NULLABLE
  • REMARKS
  • COLUMN_DEF
  • SQL_DATA_TYPE
  • SQL_DATETIME_SUB
  • CHAR_OCTET_LENGTH
  • ORDINAL_POSITION
  • IS_NULLABLE

Drivers can report additional columns.

The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.

更新日志

版本 说明
8.0.0 schema, table and column are now nullable.

范例

示例 #1 List Columns of a Table

<?php
$conn = odbc_connect($dsn, $user, $pass);
$columns = odbc_columns($conn, 'TutorialDB', 'dbo', 'test', '%');
while (($row = odbc_fetch_array($columns))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [TABLE_CAT] => TutorialDB
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => TEST
    [COLUMN_NAME] => id
    [DATA_TYPE] => 4
    [TYPE_NAME] => int
    [COLUMN_SIZE] => 10
    [BUFFER_LENGTH] => 4
    [DECIMAL_DIGITS] => 0
    [NUM_PREC_RADIX] => 10
    [NULLABLE] => 0
    [REMARKS] =>
    [COLUMN_DEF] =>
    [SQL_DATA_TYPE] => 4
    [SQL_DATETIME_SUB] =>
    [CHAR_OCTET_LENGTH] =>
    [ORDINAL_POSITION] => 1
    [IS_NULLABLE] => NO
)

参见

  • odbc_columnprivileges
  • odbc_procedurecolumns

odbc_commit

Commit an ODBC transaction

说明

bool <span class="methodname">odbc_commit ( <span class="type">resource $odbc )

Commits all pending transactions on the connection.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

返回值

成功时返回 true, 或者在失败时返回 false

odbc_connect

Connect to a datasource

说明

resource<span class="type">false <span class="methodname">odbc_connect ( <span class="methodparam">string $dsn , string $user , <span class="type">string $password [, <span class="methodparam">int $cursor_option<span class="initializer"> = SQL_CUR_USE_DRIVER ] )

The connection id returned by this functions is needed by other ODBC functions. You can have multiple connections open at once as long as they either use different db or different credentials.

With some ODBC drivers, executing a complex stored procedure may fail with an error similar to: "Cannot open a cursor on a stored procedure that has anything other than a single select statement in it". Using SQL_CUR_USE_ODBC may avoid that error. Also, some drivers don't support the optional row_number parameter in <span class="function">odbc_fetch_row. SQL_CUR_USE_ODBC might help in that case, too.

参数

dsn
The database source name for the connection. Alternatively, a DSN-less connection string can be used.

user
The username.

password
The password.

cursor_option
This sets the type of cursor to be used for this connection. This parameter is not normally needed, but can be useful for working around problems with some ODBC drivers.

The following constants are defined for cursortype:

  • SQL_CUR_USE_IF_NEEDED
  • SQL_CUR_USE_ODBC
  • SQL_CUR_USE_DRIVER

返回值

Returns an ODBC connection, 或者在失败时返回 false.

范例

示例 #1 DSN-less connections

<?php
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

// Microsoft Access
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

// Microsoft Excel
$excelFile = realpath('C:/ExcelData.xls');
$excelDir = dirname($excelFile);
$connection = odbc_connect("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir" , '', '');
?>

参见

  • For persistent connections: <span class="function">odbc_pconnect

odbc_cursor

Get cursorname

说明

string<span class="type">false <span class="methodname">odbc_cursor ( <span class="type">resource $statement )

Gets the cursorname for the given result_id.

参数

statement
The result identifier.

返回值

Returns the cursor name, as a string, 或者在失败时返回 false.

odbc_data_source

Returns information about available DSNs

说明

array<span class="type">false <span class="methodname">odbc_data_source ( <span class="methodparam">resource $odbc , int $fetch_type )

This function will return the list of available DSN (after calling it several times).

参数

odbc
ODBC 连接标识符,详见 odbc_connect

fetch_type
The fetch_type can be one of two constant types: SQL_FETCH_FIRST, SQL_FETCH_NEXT. Use SQL_FETCH_FIRST the first time this function is called, thereafter use the SQL_FETCH_NEXT.

返回值

Returns false on error, an array upon success, and null after fetching the last available DSN.

范例

示例 #1 List available DSNs

<?php
$conn = odbc_connect('dsn', 'user', 'pass');
$dsn_info = odbc_data_source($conn, SQL_FETCH_FIRST);
while ($dsn_info) {
    print_r($dsn_info);
    $dsn_info = odbc_data_source($conn, SQL_FETCH_NEXT);
}
?>

以上例程的输出类似于:

Array
(
    [server] => dsn
    [description] => ODBC Driver 17 for SQL Server
)
Array
(
    [server] => other_dsn
    [description] => Microsoft Access Driver (*.mdb, *.accdb)
)

odbc_do

别名 odbc_exec

说明

此函数是该函数的别名: odbc_exec.

odbc_error

Get the last error code

说明

string <span class="methodname">odbc_error ([ <span class="methodparam"><span class="type">resourcenull $odbc = null ] )

Returns a six-digit ODBC state, or an empty string if there has been no errors.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

返回值

If odbc is specified, the last state of that connection is returned, else the last state of any connection is returned.

This function returns meaningful value only if last odbc query failed (i.e. odbc_exec returned false).

更新日志

版本 说明
8.0.0 odbc is nullable now.

参见

  • odbc_errormsg
  • odbc_exec

odbc_errormsg

Get the last error message

说明

string <span class="methodname">odbc_errormsg ([ <span class="methodparam"><span class="type">resourcenull $odbc = null ] )

Returns a string containing the last ODBC error message, or an empty string if there has been no errors.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

返回值

If odbc is specified, the last state of that connection is returned, else the last state of any connection is returned.

This function returns meaningful value only if last odbc query failed (i.e. odbc_exec returned false).

更新日志

版本 说明
8.0.0 odbc is nullable now.

参见

  • odbc_error
  • odbc_exec

odbc_exec

Directly execute an SQL statement

说明

resource<span class="type">false <span class="methodname">odbc_exec ( <span class="type">resource $odbc , <span class="methodparam">string $query )

Sends an SQL statement to the database server.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

query
The SQL statement.

返回值

Returns an ODBC result identifier if the SQL command was executed successfully, or false on error.

更新日志

版本 说明
8.0.0 flags was removed.

参见

  • odbc_prepare
  • odbc_execute

odbc_execute

Execute a prepared statement

说明

bool <span class="methodname">odbc_execute ( <span class="methodparam">resource $statement [, <span class="type">array $params = [] ] )

Executes a statement prepared with <span class="function">odbc_prepare.

参数

statement
The result id resource, from <span class="function">odbc_prepare.

params
Parameters in parameter_array will be substituted for placeholders in the prepared statement in order. Elements of this array will be converted to strings by calling this function.

Any parameters in parameter_array which start and end with single quotes will be taken as the name of a file to read and send to the database server as the data for the appropriate placeholder.

If you wish to store a string which actually begins and ends with single quotes, you must add a space or other non-single-quote character to the beginning or end of the parameter, which will prevent the parameter from being taken as a file name. If this is not an option, then you must use another mechanism to store the string, such as executing the query directly with <span class="function">odbc_exec).

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 odbc_execute and <span class="function">odbc_prepare example

In the following code, $success will only be true if all three parameters to myproc are IN parameters:

<?php
$a = 1;
$b = 2;
$c = 3;
$stmt    = odbc_prepare($conn, 'CALL myproc(?,?,?)');
$success = odbc_execute($stmt, array($a, $b, $c));
?>

If you need to call a stored procedure using INOUT or OUT parameters, the recommended workaround is to use a native extension for your database (for example, oci8 for Oracle).

参见

  • odbc_prepare

odbc_fetch_array

Fetch a result row as an associative array

说明

array<span class="type">false <span class="methodname">odbc_fetch_array ( <span class="methodparam">resource $statement [, <span class="type">int $row = -1 ] )

Fetch an associative array from an ODBC query.

参数

statement
The result resource from odbc_exec.

row
Optionally choose which row number to retrieve.

返回值

Returns an array that corresponds to the fetched row, or false if there are no more rows.

注释

Note: This function exists when compiled with DBMaker, IBM DB2 or UnixODBC support.

参见

  • odbc_fetch_row
  • odbc_fetch_object
  • odbc_num_rows

odbc_fetch_into

Fetch one result row into array

说明

int<span class="type">false <span class="methodname">odbc_fetch_into ( <span class="methodparam">resource $statement , <span class="type">array &$array [, <span class="methodparam">int $row<span class="initializer"> = 0 ] )

Fetch one result row into array.

参数

statement
The result resource.

array
The result array that can be of any type since it will be converted to type array. The array will contain the column values starting at array index 0.

row
The row number.

返回值

Returns the number of columns in the result; false on error.

范例

示例 #1 odbc_fetch_into examples

<?php
$rc = odbc_fetch_into($res_id, $my_array);
?>

or

<?php
$rc = odbc_fetch_into($res_id, $my_array, 2);
?>

odbc_fetch_object

Fetch a result row as an object

说明

stdClass<span class="type">false <span class="methodname">odbc_fetch_object ( <span class="methodparam">resource $statement [, <span class="type">int $row = -1 ] )

Fetch an object from an ODBC query.

参数

statement
The result resource from odbc_exec.

row
Optionally choose which row number to retrieve.

返回值

Returns an object that corresponds to the fetched row, or false if there are no more rows.

注释

Note: This function exists when compiled with DBMaker, IBM DB2 or UnixODBC support.

参见

  • odbc_fetch_row
  • odbc_fetch_array
  • odbc_num_rows

odbc_fetch_row

Fetch a row

说明

bool <span class="methodname">odbc_fetch_row ( <span class="methodparam">resource $statement [, <span class="type">int<span class="type">null $row = null ] )

Fetches a row of the data that was returned by <span class="function">odbc_do or <span class="function">odbc_exec. After <span class="function">odbc_fetch_row is called, the fields of that row can be accessed with odbc_result.

参数

statement
The result identifier.

row
If row is not specified, <span class="function">odbc_fetch_row will try to fetch the next row in the result set. Calls to <span class="function">odbc_fetch_row with and without row can be mixed.

To step through the result more than once, you can call <span class="function">odbc_fetch_row with row 1, and then continue doing odbc_fetch_row without row to review the result. If a driver doesn't support fetching rows by number, the row parameter is ignored.

返回值

Returns true if there was a row, false otherwise.

更新日志

版本 说明
8.0.0 row is nullable now.

odbc_field_len

Get the length (precision) of a field

说明

int<span class="type">false <span class="methodname">odbc_field_len ( <span class="methodparam">resource $statement , <span class="type">int $field )

Gets the length of the field referenced by number in the given result identifier.

参数

statement
The result identifier.

field
The field number. Field numbering starts at 1.

返回值

Returns the field length, or false on error.

参见

  • odbc_field_scale to get the scale of a floating point number

odbc_field_name

Get the columnname

说明

string<span class="type">false <span class="methodname">odbc_field_name ( <span class="methodparam">resource $statement , <span class="type">int $field )

Gets the name of the field occupying the given column number in the given result identifier.

参数

statement
The result identifier.

field
The field number. Field numbering starts at 1.

返回值

Returns the field name as a string, or false on error.

odbc_field_num

Return column number

说明

int<span class="type">false <span class="methodname">odbc_field_num ( <span class="methodparam">resource $statement , <span class="type">string $field )

Gets the number of the column slot that corresponds to the named field in the given result identifier.

参数

statement
The result identifier.

field
The field name.

返回值

Returns the field number as a integer, or false on error. Field numbering starts at 1.

odbc_field_precision

别名 odbc_field_len

说明

此函数是该函数的别名: odbc_field_len.

参见

  • odbc_field_scale to get the scale of a floating point number.

odbc_field_scale

Get the scale of a field

说明

int<span class="type">false <span class="methodname">odbc_field_scale ( <span class="methodparam">resource $statement , <span class="type">int $field )

Gets the scale of the field referenced by number in the given result identifier.

参数

statement
The result identifier.

field
The field number. Field numbering starts at 1.

返回值

Returns the field scale as a integer, or false on error.

odbc_field_type

Datatype of a field

说明

string<span class="type">false <span class="methodname">odbc_field_type ( <span class="methodparam">resource $statement , <span class="type">int $field )

Gets the SQL type of the field referenced by number in the given result identifier.

参数

statement
The result identifier.

field
The field number. Field numbering starts at 1.

返回值

Returns the field type as a string, or false on error.

odbc_foreignkeys

Retrieves a list of foreign keys

说明

resource<span class="type">false <span class="methodname">odbc_foreignkeys ( <span class="methodparam">resource $odbc , <span class="type">stringnull $pk_catalog , <span class="type">string $pk_schema , <span class="methodparam">string $pk_table , string $fk_catalog , <span class="type">string $fk_schema , <span class="methodparam">string $fk_table )

Retrieves a list of foreign keys in the specified table or a list of foreign keys in other tables that refer to the primary key in the specified table

参数

odbc
ODBC 连接标识符,详见 odbc_connect

pk_catalog
The catalog ('qualifier' in ODBC 2 parlance) of the primary key table.

pk_schema
The schema ('owner' in ODBC 2 parlance) of the primary key table.

pk_table
The primary key table.

pk_catalog
The catalog ('qualifier' in ODBC 2 parlance) of the foreign key table.

fk_schema
The schema ('owner' in ODBC 2 parlance) of the foreign key table.

fk_table
The foreign key table.

返回值

Returns an ODBC result identifier 或者在失败时返回 false.

The result set has the following columns:

  • PKTABLE_CAT
  • PKTABLE_SCHEM
  • PKTABLE_NAME
  • PKCOLUMN_NAME
  • FKTABLE_CAT
  • FKTABLE_SCHEM
  • FKTABLE_NAME
  • FKCOLUMN_NAME
  • KEY_SEQ
  • UPDATE_RULE
  • DELETE_RULE
  • FK_NAME
  • PK_NAME
  • DEFERRABILITY

Drivers can report additional columns.

If the foreign keys associated with a primary key are requested, the result set is ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME and KEY_SEQ. If the primary keys associated with a foreign key are requested, the result set is ordered by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME and KEY_SEQ.

If pk_table contains a table name, <span class="function">odbc_foreignkeys returns a result set containing the primary key of the specified table and all of the foreign keys that refer to it.

If fk_table contains a table name, <span class="function">odbc_foreignkeys returns a result set containing all of the foreign keys in the specified table and the primary keys (in other tables) to which they refer.

If both pk_table and fk_table contain table names, <span class="function">odbc_foreignkeys returns the foreign keys in the table specified in fk_table that refer to the primary key of the table specified in pk_table. This should be one key at most.

参见

  • odbc_tables
  • odbc_primarykeys

odbc_free_result

Free resources associated with a result

说明

bool <span class="methodname">odbc_free_result ( <span class="methodparam">resource $statement )

Free resources associated with a result.

odbc_free_result only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script is finished.

参数

statement
The result identifier.

返回值

Always returns true.

注释

Note:

If auto-commit is disabled (see <span class="function">odbc_autocommit) and you call <span class="function">odbc_free_result before committing, all pending transactions are rolled back.

odbc_gettypeinfo

Retrieves information about data types supported by the data source

说明

resource<span class="type">false <span class="methodname">odbc_gettypeinfo ( <span class="methodparam">resource $odbc [, int $data_type = 0 ] )

Retrieves information about data types supported by the data source.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

data_type
The data type, which can be used to restrict the information to a single data type.

返回值

Returns an ODBC result identifier or false on failure.

The result set has the following columns:

  • TYPE_NAME
  • DATA_TYPE
  • PRECISION
  • LITERAL_PREFIX
  • LITERAL_SUFFIX
  • CREATE_PARAMS
  • NULLABLE
  • CASE_SENSITIVE
  • SEARCHABLE
  • UNSIGNED_ATTRIBUTE
  • MONEY
  • AUTO_INCREMENT
  • LOCAL_TYPE_NAME
  • MINIMUM_SCALE
  • MAXIMUM_SCALE

The result set is ordered by DATA_TYPE and TYPE_NAME.

odbc_longreadlen

Handling of LONG columns

说明

bool <span class="methodname">odbc_longreadlen ( <span class="methodparam">resource $statement , <span class="type">int $length )

Controls handling of LONG, LONGVARCHAR and LONGVARBINARY columns. The default length can be set using the uodbc.defaultlrl php.ini directive.

参数

statement
The result identifier.

length
The number of bytes returned to PHP is controlled by the parameter length. If it is set to 0, long column data is passed through to the client (i.e. printed) when retrieved with <span class="function">odbc_result.

返回值

成功时返回 true, 或者在失败时返回 false

注释

Note:

Handling of LONGVARBINARY columns is also affected by <span class="function">odbc_binmode.

odbc_next_result

Checks if multiple results are available

说明

bool <span class="methodname">odbc_next_result ( <span class="methodparam">resource $statement )

Checks if there are more result sets available as well as allowing access to the next result set via <span class="function">odbc_fetch_array, <span class="function">odbc_fetch_row, <span class="function">odbc_result, etc.

参数

statement
The result identifier.

返回值

Returns true if there are more result sets, false otherwise.

范例

示例 #1 odbc_next_result

<?php
$r_Connection = odbc_connect($dsn, $username, $password);

$s_SQL = <<<END_SQL
SELECT 'A'
SELECT 'B'
SELECT 'C'
END_SQL;

$r_Results = odbc_exec($r_Connection, $s_SQL);

$a_Row1 = odbc_fetch_array($r_Results);
$a_Row2 = odbc_fetch_array($r_Results);
echo "Dump first result set";
var_dump($a_Row1, $a_Row2);

echo "Get second results set ";
var_dump(odbc_next_result($r_Results));

$a_Row1 = odbc_fetch_array($r_Results);
$a_Row2 = odbc_fetch_array($r_Results);
echo "Dump second result set ";
var_dump($a_Row1, $a_Row2);

echo "Get third results set ";
var_dump(odbc_next_result($r_Results));

$a_Row1 = odbc_fetch_array($r_Results);
$a_Row2 = odbc_fetch_array($r_Results);
echo "Dump third result set ";
var_dump($a_Row1, $a_Row2);

echo "Try for a fourth result set ";
var_dump(odbc_next_result($r_Results));
?>

以上例程会输出:

Dump first result set array(1) {
  ["A"]=>
  string(1) "A"
}
bool(false)
Get second results set bool(true)
Dump second result set array(1) {
  ["B"]=>
  string(1) "B"
}
bool(false)
Get third results set bool(true)
Dump third result set array(1) {
  ["C"]=>
  string(1) "C"
}
bool(false)
Try for a fourth result set bool(false)

odbc_num_fields

Number of columns in a result

说明

int <span class="methodname">odbc_num_fields ( <span class="methodparam">resource $statement )

Gets the number of fields (columns) in an ODBC result.

参数

statement
The result identifier returned by <span class="function">odbc_exec.

返回值

Returns the number of fields, or -1 on error.

odbc_num_rows

Number of rows in a result

说明

int <span class="methodname">odbc_num_rows ( <span class="methodparam">resource $statement )

Gets the number of rows in a result. For INSERT, UPDATE and DELETE statements odbc_num_rows returns the number of rows affected. For a SELECT clause this can be the number of rows available.

参数

statement
The result identifier returned by <span class="function">odbc_exec.

返回值

Returns the number of rows in an ODBC result. This function will return -1 on error.

注释

Note:

Using odbc_num_rows to determine the number of rows available after a SELECT will return -1 with many drivers.

odbc_pconnect

Open a persistent database connection

说明

resource<span class="type">false <span class="methodname">odbc_pconnect ( <span class="methodparam">string $dsn , string $user , <span class="type">string $password [, <span class="methodparam">int $cursor_option<span class="initializer"> = SQL_CUR_USE_DRIVER ] )

Opens a persistent database connection.

This function is much like odbc_connect, except that the connection is not really closed when the script has finished. Future requests for a connection with the same dsn, user, password combination (via odbc_connect and odbc_pconnect) can reuse the persistent connection.

参数

See odbc_connect for details.

返回值

Returns an ODBC connection, 或者在失败时返回 false. error.

注释

Note: Persistent connections have no effect if PHP is used as a CGI program.

参见

odbc_prepare

Prepares a statement for execution

说明

resource<span class="type">false <span class="methodname">odbc_prepare ( <span class="methodparam">resource $odbc , string $query )

Prepares a statement for execution. The result identifier can be used later to execute the statement with <span class="function">odbc_execute.

Some databases (such as IBM DB2, MS SQL Server, and Oracle) support stored procedures that accept parameters of type IN, INOUT, and OUT as defined by the ODBC specification. However, the Unified ODBC driver currently only supports parameters of type IN to stored procedures.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

query
The query string statement being prepared.

返回值

Returns an ODBC result identifier if the SQL command was prepared successfully. Returns false on error.

范例

示例 #1 odbc_execute and <span class="function">odbc_prepare example

In the following code, $success will only be true if all three parameters to myproc are IN parameters:

<?php
$a = 1;
$b = 2;
$c = 3;
$stmt    = odbc_prepare($conn, 'CALL myproc(?,?,?)');
$success = odbc_execute($stmt, array($a, $b, $c));
?>

If you need to call a stored procedure using INOUT or OUT parameters, the recommended workaround is to use a native extension for your database (for example, oci8 for Oracle).

参见

  • odbc_execute

odbc_primarykeys

Gets the primary keys for a table

说明

resource<span class="type">false <span class="methodname">odbc_primarykeys ( <span class="methodparam">resource $odbc , <span class="type">stringnull $catalog , <span class="type">string $schema , <span class="methodparam">string $table )

Returns a result identifier that can be used to fetch the column names that comprise the primary key for a table.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance).

table

返回值

Returns an ODBC result identifier 或者在失败时返回 false.

The result set has the following columns:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • COLUMN_NAME
  • KEY_SEQ
  • PK_NAME

Drivers can report additional columns.

The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME and KEY_SEQ.

范例

示例 #1 List primary Keys of a Column

<?php
$conn = odbc_connect($dsn, $user, $pass);
$primarykeys = odbc_primarykeys($conn, 'TutorialDB', 'dbo', 'TEST');
while (($row = odbc_fetch_array($primarykeys))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [TABLE_CAT] => TutorialDB
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => TEST
    [COLUMN_NAME] => id
    [KEY_SEQ] => 1
    [PK_NAME] => PK__TEST__3213E83FE141F843
)

参见

  • odbc_tables
  • odbc_foreignkeys

odbc_procedurecolumns

Retrieve information about parameters to procedures

说明

resource<span class="type">false <span class="methodname">odbc_procedurecolumns ( <span class="methodparam">resource $odbc [, <span class="type">stringnull $catalog = null [, <span class="type">stringnull $schema = null [, <span class="methodparam"><span class="type">stringnull $procedure = null [, <span class="type">stringnull $column = null ]]]] )

Retrieve information about parameters to procedures.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance). 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

procedure
The proc. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

column
The column. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

返回值

Returns the list of input and output parameters, as well as the columns that make up the result set for the specified procedures. Returns an ODBC result identifier 或者在失败时返回 false.

The result set has the following columns:

  • PROCEDURE_CAT
  • PROCEDURE_SCHEM
  • PROCEDURE_NAME
  • COLUMN_NAME
  • COLUMN_TYPE
  • DATA_TYPE
  • TYPE_NAME
  • COLUMN_SIZE
  • BUFFER_LENGTH
  • DECIMAL_DIGITS
  • NUM_PREC_RADIX
  • NULLABLE
  • REMARKS
  • COLUMN_DEF
  • SQL_DATA_TYPE
  • SQL_DATETIME_SUB
  • CHAR_OCTET_LENGTH
  • ORDINAL_POSITION
  • IS_NULLABLE

Drivers can report additional columns.

The result set is ordered by PROCEDURE_CAT, PROCEDURE_SCHEM, PROCEDURE_NAME and COLUMN_TYPE.

更新日志

版本 说明
8.0.0 Prior to this version, the function could only be called with either one or five arguments.

范例

示例 #1 List Columns of a stored Procedure

<?php
$conn = odbc_connect($dsn, $user, $pass);
$columns = odbc_procedurecolumns($conn, 'TutorialDB', 'dbo', 'GetEmployeeSalesYTD;1', '%');
while (($row = odbc_fetch_array($columns))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [PROCEDURE_CAT] => TutorialDB
    [PROCEDURE_SCHEM] => dbo
    [PROCEDURE_NAME] => GetEmployeeSalesYTD;1
    [COLUMN_NAME] => @SalesPerson
    [COLUMN_TYPE] => 1
    [DATA_TYPE] => -9
    [TYPE_NAME] => nvarchar
    [COLUMN_SIZE] => 50
    [BUFFER_LENGTH] => 100
    [DECIMAL_DIGITS] =>
    [NUM_PREC_RADIX] =>
    [NULLABLE] => 1
    [REMARKS] =>
    [COLUMN_DEF] =>
    [SQL_DATA_TYPE] => -9
    [SQL_DATETIME_SUB] =>
    [CHAR_OCTET_LENGTH] => 100
    [ORDINAL_POSITION] => 1
    [IS_NULLABLE] => YES
)

参见

  • odbc_columns

odbc_procedures

Get the list of procedures stored in a specific data source

说明

resource<span class="type">false <span class="methodname">odbc_procedures ( <span class="methodparam">resource $odbc [, <span class="type">stringnull $catalog = null [, <span class="type">stringnull $schema = null [, <span class="methodparam"><span class="type">stringnull $procedure = null ]]] )

Lists all procedures in the requested range.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance). 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

procedure
The name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

返回值

Returns an ODBC result identifier containing the information 或者在失败时返回 false.

The result set has the following columns:

  • PROCEDURE_CAT
  • PROCEDURE_SCHEM
  • PROCEDURE_NAME
  • NUM_INPUT_PARAMS
  • NUM_OUTPUT_PARAMS
  • NUM_RESULT_SETS
  • REMARKS
  • PROCEDURE_TYPE

Drivers can report additional columns.

The result set is ordered by PROCEDURE_CAT, PROCEDURE_SCHEMA and PROCEDURE_NAME.

更新日志

版本 说明
8.0.0 Prior to this version, the function could only be called with either one or four arguments.

范例

示例 #1 List stored Procedures of a Database

<?php
$conn = odbc_connect($dsn, $user, $pass);
$procedures = odbc_procedures($conn, $catalog, $schema, '%');
while (($row = odbc_fetch_array($procedures))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [PROCEDURE_CAT] => TutorialDB
    [PROCEDURE_SCHEM] => dbo
    [PROCEDURE_NAME] => GetEmployeeSalesYTD;1
    [NUM_INPUT_PARAMS] => -1
    [NUM_OUTPUT_PARAMS] => -1
    [NUM_RESULT_SETS] => -1
    [REMARKS] =>
    [PROCEDURE_TYPE] => 2
)

参见

  • odbc_procedurecolumns
  • odbc_tables

odbc_result_all

Print result as HTML table

说明

int<span class="type">false <span class="methodname">odbc_result_all ( <span class="methodparam">resource $statement [, <span class="type">string $format = "" ] )

Prints all rows from a result identifier produced by <span class="function">odbc_exec. The result is printed in HTML table format. The data is not escaped.

This function is not supposed to be used in production environments; it is merely meant for development purposes, to get a result set quickly rendered.

参数

statement
The result identifier.

format
Additional overall table formatting.

返回值

Returns the number of rows in the result or false on error.

odbc_result

Get result data

说明

string<span class="type">boolnull <span class="methodname">odbc_result ( <span class="type">resource $statement , <span class="methodparam"><span class="type">stringint $field )

Get result data

参数

statement
The ODBC resource.

field
The field name being retrieved. It can either be an integer containing the column number of the field you want; or it can be a string containing the name of the field.

返回值

Returns the string contents of the field, false on error, null for NULL data, or true for binary data.

范例

The first call to odbc_result returns the value of the third field in the current record of the query result. The second function call to odbc_result returns the value of the field whose field name is "val" in the current record of the query result. An error occurs if a column number parameter for a field is less than one or exceeds the number of columns (or fields) in the current record. Similarly, an error occurs if a field with a name that is not one of the fieldnames of the table(s) that is(are) being queried.

示例 #1 odbc_result examples

<?php
$item_3   = odbc_result($Query_ID, 3);
$item_val = odbc_result($Query_ID, "val");
?>

注释

Field indices start from 1. Regarding the way binary or long column data is returned refer to odbc_binmode and odbc_longreadlen.

odbc_rollback

Rollback a transaction

说明

bool <span class="methodname">odbc_rollback ( <span class="methodparam">resource $odbc )

Rolls back all pending statements on the connection.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

返回值

成功时返回 true, 或者在失败时返回 false

odbc_setoption

Adjust ODBC settings

说明

bool <span class="methodname">odbc_setoption ( <span class="methodparam">resource $odbc , int $which , int $option , <span class="type">int $value )

This function allows fiddling with the ODBC options for a particular connection or query result. It was written to help find work around to problems in quirky ODBC drivers. You should probably only use this function if you are an ODBC programmer and understand the effects the various options will have. You will certainly need a good ODBC reference to explain all the different options and values that can be used. Different driver versions support different options.

Because the effects may vary depending on the ODBC driver, use of this function in scripts to be made publicly available is strongly discouraged. Also, some ODBC options are not available to this function because they must be set before the connection is established or the query is prepared. However, if on a particular job it can make PHP work so your boss doesn't tell you to use a commercial product, that's all that really matters.

参数

odbc
Is a connection id or result id on which to change the settings. For SQLSetConnectOption(), this is a connection id. For SQLSetStmtOption(), this is a result id.

which
Is the ODBC function to use. The value should be 1 for SQLSetConnectOption() and 2 for SQLSetStmtOption().

option
The option to set.

value
The value for the given option.

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 odbc_setoption examples

<?php
// 1. Option 102 of SQLSetConnectOption() is SQL_AUTOCOMMIT.
//    Value 1 of SQL_AUTOCOMMIT is SQL_AUTOCOMMIT_ON.
//    This example has the same effect as
//    odbc_autocommit($conn, true);

odbc_setoption($conn, 1, 102, 1);

// 2. Option 0 of SQLSetStmtOption() is SQL_QUERY_TIMEOUT.
//    This example sets the query to timeout after 30 seconds.

$result = odbc_prepare($conn, $sql);
odbc_setoption($result, 2, 0, 30);
odbc_execute($result);
?>

odbc_specialcolumns

Retrieves special columns

说明

resource<span class="type">false <span class="methodname">odbc_specialcolumns ( <span class="methodparam">resource $odbc , int $type , <span class="type">stringnull $catalog , <span class="type">string $schema , <span class="methodparam">string $table , int $scope , int $nullable )

Retrieves either the optimal set of columns that uniquely identifies a row in the table, or columns that are automatically updated when any value in the row is updated by a transaction.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

type
When the type argument is SQL_BEST_ROWID, odbc_specialcolumns returns the column or columns that uniquely identify each row in the table. <span class="simpara"> When the type argument is SQL_ROWVER, <span class="function">odbc_specialcolumns returns the column or columns in the specified table, if any, that are automatically updated by the data source when any value in the row is updated by any transaction.

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance).

table
The table.

scope
The scope, which orders the result set. One of SQL_SCOPE_CURROW, SQL_SCOPE_TRANSACTION or SQL_SCOPE_SESSION.

nullable
Determines whether to return special columns that can have a NULL value. One of SQL_NO_NULLS or SQL_NULLABLE.

返回值

Returns an ODBC result identifier or false on failure.

The result set has the following columns:

  • SCOPE
  • COLUMN_NAME
  • DATA_TYPE
  • TYPE_NAME
  • COLUMN_SIZE
  • BUFFER_LENGTH
  • DECIMAL_DIGITS
  • PSEUDO_COLUMN

Drivers can report additional columns.

The result set is ordered by SCOPE.

参见

  • odbc_tables

odbc_statistics

Retrieve statistics about a table

说明

resource<span class="type">false <span class="methodname">odbc_statistics ( <span class="methodparam">resource $odbc , <span class="type">stringnull $catalog , <span class="type">string $schema , <span class="methodparam">string $table , int $unique , int $accuracy )

Get statistics about a table and its indexes.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance).

table
The table name.

unique
The type of the index. One of SQL_INDEX_UNIQUE or SQL_INDEX_ALL.

accuracy
One of SQL_ENSURE or SQL_QUICK. The latter requests that the driver retrieve the CARDINALITY and PAGES only if they are readily available from the server.

返回值

Returns an ODBC result identifier 或者在失败时返回 false.

The result set has the following columns:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • NON_UNIQUE
  • INDEX_QUALIFIER
  • INDEX_NAME
  • TYPE
  • ORDINAL_POSITION
  • COLUMN_NAME
  • ASC_OR_DESC
  • CARDINALITY
  • PAGES
  • FILTER_CONDITION

Drivers can report additional columns.

The result set is ordered by NON_UNIQUE, TYPE, INDEX_QUALIFIER, INDEX_NAME and ORDINAL_POSITION.

范例

示例 #1 List Statistics of a Table

<?php
$conn = odbc_connect($dsn, $user, $pass);
$statistics = odbc_statistics($conn, 'TutorialDB', 'dbo', 'TEST', SQL_INDEX_UNIQUE, SQL_QUICK);
while (($row = odbc_fetch_array($statistics))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [TABLE_CAT] => TutorialDB
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => TEST
    [NON_UNIQUE] =>
    [INDEX_QUALIFIER] =>
    [INDEX_NAME] =>
    [TYPE] => 0
    [ORDINAL_POSITION] =>
    [COLUMN_NAME] =>
    [ASC_OR_DESC] =>
    [CARDINALITY] => 15
    [PAGES] => 3
    [FILTER_CONDITION] =>
)

参见

  • odbc_tables

odbc_tableprivileges

Lists tables and the privileges associated with each table

说明

resource<span class="type">false <span class="methodname">odbc_tableprivileges ( <span class="methodparam">resource $odbc , <span class="type">stringnull $catalog , <span class="type">string $schema , <span class="methodparam">string $table )

Lists tables in the requested range and the privileges associated with each table.

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance). 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

table
The name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

返回值

An ODBC result identifier 或者在失败时返回 false.

The result set has the following columns:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • GRANTOR
  • GRANTEE
  • PRIVILEGE
  • IS_GRANTABLE

Drivers can report additional columns.

The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, PRIVILEGE and GRANTEE.

范例

示例 #1 List Privileges of a Table

<?php
$conn = odbc_connect($dsn, $user, $pass);
$privileges = odbc_tableprivileges($conn, 'SalesOrders', 'dbo', 'Orders');
while (($row = odbc_fetch_array($privileges))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [TABLE_CAT] => SalesOrders
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => Orders
    [GRANTOR] => dbo
    [GRANTEE] => dbo
    [PRIVILEGE] => DELETE
    [IS_GRANTABLE] => YES
)

参见

  • odbc_tables

odbc_tables

Get the list of table names stored in a specific data source

说明

resource<span class="type">false <span class="methodname">odbc_tables ( <span class="type">resource $odbc [, <span class="methodparam"><span class="type">stringnull $catalog = null [, <span class="type">stringnull $schema = null [, <span class="methodparam"><span class="type">stringnull $table = null [, <span class="methodparam"><span class="type">stringnull $types = null ]]]] )

Lists all tables in the requested range.

To support enumeration of qualifiers, owners, and table types, the following special semantics for the catalog, schema, table, and table_type are available:

  • If catalog is a single percent character (%) and schema and table are empty strings, then the result set contains a list of valid qualifiers for the data source. (All columns except the TABLE_QUALIFIER column contain NULLs.)
  • If schema is a single percent character (%) and catalog and table are empty strings, then the result set contains a list of valid owners for the data source. (All columns except the TABLE_OWNER column contain NULLs.)
  • If table_type is a single percent character (%) and catalog, schema and table are empty strings, then the result set contains a list of valid table types for the data source. (All columns except the TABLE_TYPE column contain NULLs.)

参数

odbc
ODBC 连接标识符,详见 odbc_connect

catalog
The catalog ('qualifier' in ODBC 2 parlance).

schema
The schema ('owner' in ODBC 2 parlance). 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

table
The name. 此参数接受下列查询模式: % 来匹配零到多个字符, _ 来匹配单个字符。

types
If table_type is not an empty string, it must contain a list of comma-separated values for the types of interest; each value may be enclosed in single quotes (') or unquoted. For example, 'TABLE','VIEW' or TABLE, VIEW. If the data source does not support a specified table type, odbc_tables does not return any results for that type.

返回值

Returns an ODBC result identifier containing the information 或者在失败时返回 false.

The result set has the following columns:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • TABLE_TYPE
  • REMARKS

Drivers can report additional columns.

The result set is ordered by TABLE_TYPE, TABLE_CAT, TABLE_SCHEM and TABLE_NAME.

更新日志

版本 说明
8.0.0 schema, table and types are now nullable.

范例

示例 #1 List Tables in a Catalog

<?php
$conn = odbc_connect($dsn, $user, $pass);
$tables = odbc_tables($conn, 'SalesOrders', 'dbo', '%', 'TABLE');
while (($row = odbc_fetch_array($tables))) {
    print_r($row);
    break; // further rows omitted for brevity
}
?>

以上例程的输出类似于:

Array
(
    [TABLE_CAT] => SalesOrders
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => Orders
    [TABLE_TYPE] => TABLE
    [REMARKS] =>
)

参见

  • odbc_tableprivileges
  • odbc_columns
  • odbc_specialcolumns
  • odbc_statistics
  • odbc_procedures

目录


本站为非盈利网站,作品由网友提供上传,如无意中有侵犯您的版权,请联系删除