odbc_connect

PHP 4, PHP 5, PHP 7, PHP 8
odbc_connect - Connect to a datasource
Manual
Code Examples

odbc_connect(
     string$dsn,
     string$user,
     string$password,
     [int$cursor_option = SQL_CUR_USE_DRIVER]
): resource|false

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 odbc_fetch_row. SQL_CUR_USE_ODBC might help in that case, too.

Parameters

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

Return Values

Returns an ODBC connection, or false on failure.

Related Functions

Example of odbc_connect

Show all examples for odbc_connect

PHP Version: