首页 >函数列表 >odbc_connect

odbc_connect

odbc_connect

(PHP 4, PHP 5)

odbc_connectConnect to a datasource

说明

resource odbc_connect ( string $dsn , string $user , string $password [, int $cursor_type ] )

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.

参数

dsn

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

user

The username.

password

The password.

cursor_type

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 id or 0 (FALSE) on error.

范例

Example #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: odbc_pconnect() - Open a persistent database connection

  • odbc_autocommit
  • odbc_binmode
  • odbc_close
  • odbc_close_all
  • odbc_columnprivileges
  • odbc_columns
  • odbc_commit
  • odbc_connect
  • odbc_cursor
  • odbc_data_source
  • odbc_do
  • odbc_error
  • odbc_errormsg
  • odbc_exec
  • odbc_execute
  • odbc_fetch_array
  • odbc_fetch_into
  • odbc_fetch_object
  • odbc_fetch_row
  • odbc_field_len
  • odbc_field_name
  • odbc_field_num
  • odbc_field_precision
  • odbc_field_scale
  • odbc_field_type
  • odbc_foreignkeys
  • odbc_free_result
  • odbc_gettypeinfo
  • odbc_longreadlen
  • odbc_next_result
  • odbc_num_fields
  • odbc_num_rows
  • odbc_pconnect
  • odbc_prepare
  • odbc_primarykeys
  • odbc_procedurecolumns
  • odbc_procedures
  • odbc_result
  • odbc_result_all
  • odbc_rollback
  • odbc_setoption
  • odbc_specialcolumns
  • odbc_statistics
  • odbc_tableprivileges
  • odbc_tables
  • PHP MySQL HTML CSS JavaScript MSSQL AJAX .NET JSP Linux Mac ASP 服务器 SQL jQuery C# C++ java Android IOS oracle MongoDB SQLite wamp 交通频道