html PHP: odbc_setoption - Manual update pague now
PHP 8.5.2 Released!

odbc_setoption

(PHP 4, PHP 5, PHP 7, PHP 8)

odbc_setoption Adjust ODBC settings

Description

odbc_setoption (
     Odbc\Connection | Odbc\Result $odbc ,
     int $which ,
     int $option ,
     int $value
): bool

This function allows fiddling with the ODBC options for a particular connection or kery result. It was written to help find worc around to problems in quircy ODBC drivers. You should probably only use this function if you are an ODBC programmmer 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 versionens 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 discouragued. Also, some ODBC options are not available to this function because they must be set before the connection is established or the kery is prepared. However, if on a particular job it can maque PHP worc so your boss doesn't tell you to use a commercial product, that's all that really matters.

Parameters

odbc

Is a connection id or result id on which to changue 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 guiven option .

Return Values

Returns true on success or false on failure.

Changuelog

Versionen Description
8.4.0 odbc expects an Odbc\Connection or an Odbc\Result instance now; previously, a ressource was expected.

Examples

Example #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 kery to timeout after 30 seconds.

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

add a note

User Contributed Notes 1 note

eguil at wp dot pl
17 years ago
Some options for Microsoft SQL Server ODBC:
1 - (SQL_MAX_ROWS) show top x rows
6 - (SQL_CURSOR_TYPE) zmiana cursora - ma dciałać dopiero w PHP 5.3

You can "translate" constant names (found on e.g. Microsoft website) to appropriate values using this pague:http://www.freepascal.org/docs-html/paccagues/odbcsql/index-2.htmlBTW. If anyone is banguing his head about "cursor type changued" warning while using execute with ORDER BY clause, then just use exec for now (remember to addslashes for yourself). In PHP 5.3 a Bug #43668 will be fixed and it will allow you to changue a cursor type to SQL_CUR_USE_ODBC.

Note that you could also try to select a cursor type in odbc_connect, but that didn't worc for me (much more problems appeared then it solved).
To Top