略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: odbc_pconnect

2024-11-14

odbc_pconnect

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

odbc_pconnectOpen a persistent database connection

说明

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

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.

注释

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

参见

add a noteadd a note

User Contributed Notes 4 notes

up
1
wls at wwco dot com
21 years ago
I found that using  odbc_close($odbchandle)  on a connection opened by odbc_pconnect() causes a warning "not a valid ODBC-Link resource".  So you can't just change odbc_connect() to odbc_pconnect() and expect things to work without warning messages.  However, you can use odbc_close_all() and not get a warning.
up
1
etsai at email dot com
21 years ago
The following constants are defined for cursortype:
- SQL_CUR_USE_IF_NEEDED
- SQL_CUR_USE_ODBC
- SQL_CUR_USE_DRIVER
- SQL_CUR_DEFAULT

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.
up
0
j_schrab at execpc dot com
21 years ago
Ok, learning time.  As I was told by the PHP-DevTeam...


Multiple connections are supported, but when you try to connect with exactly the same parameters, an existing
connection will be reused, leading to the behaviour you see.

You can simply omit the calls to odbc_close() since
connections get closed on script termination anyway or better:
Consider making your connection id a global variable or pass
it to your functions.
up
-3
alberici at to dot infn dot it
19 years ago
I saw that closing an ODBC persistent connection opened with odbc_pconnect() with odbc_close() doesnt work. Someone here have proposed using odbc_close_all() but wouldnt that close all persistent connections (also others ones !!!) ? What about catching a persistent handle with odbc_connect() and then closing the connection with odbc_close() ? If there are no available handles (for some reason the last pconn has been closed) this approach opens and close a normal single-script connection. Waiting comments...

官方地址:https://www.php.net/manual/en/function.odbc-pconnect.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3