Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38632 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41802 invoked from network); 26 Jun 2008 08:46:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2008 08:46:15 -0000 Authentication-Results: pb1.pair.com header.from=gomar.bijl@bu400.nl; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=gomar.bijl@bu400.nl; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain bu400.nl from 80.248.34.171 cause and error) X-PHP-List-Original-Sender: gomar.bijl@bu400.nl X-Host-Fingerprint: 80.248.34.171 smtp.mailfilter.xb.nl Received: from [80.248.34.171] ([80.248.34.171:45730] helo=smtp.mailfilter.xb.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/84-13482-45753684 for ; Thu, 26 Jun 2008 04:46:13 -0400 Received: from NL67S011.cal-consult.nl ([217.17.142.243]) by smtp.mailfilter.xb.nl with ESMTP id m5Q8k6qV007637 for ; Thu, 26 Jun 2008 10:46:07 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C8D769.1199524A" Date: Thu, 26 Jun 2008 10:46:04 +0200 Message-ID: <6873E3E399117E4BA9FD3854A3DB93814B67EC@NL67S011.cal-consult.nl> To: Subject: [PATCH] ODBC_Pconnect should not Commit/Rollback database transactions of previous data From: gomar.bijl@bu400.nl ("Bijl, Gomar") ------_=_NextPart_001_01C8D769.1199524A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi We have a problem with the (ODBC) persistent database connection. We have found that every PHP-session, using the same dsn, user and password, are getting the same persistent connection by a reasonable chance. Also meaning that if a database transaction was not finished, other PHP-session can do a rollback or commit of that transaction.=20 Due to resource problems with (temporarily) connections the persistent connections are used, so we do. But "leftovers" of database transactions were not intended.=20 Also if one want to open an another connection in one PHP-session the result is the same connection. (E.g. we use a DB-log-file to log errors en warning, so you don't want to do a rollback on the DB-log-file, in peculiar.) To overcome these problems one has to tag the connections. I suggest to use a new parameter on ODBC_(p)connect: Tag, a string parameter. If used it tries to re-connect to the connection with the same tag, if not existing it creates a new-connection.=20 For example the tag parameter is filled with the session_ID() to ensure that a connection is bounded to one PHP-session. But also an extension on this value is possible: (Session_ID() + 'Log') or (Session_ID() + 'Data'). And if somebody does not uses this tag parameter, it works in the old way, so these solution is downwards compatible. So the adjusted description will be: resource odbc_pconnect (string $dsn , string $user , string $password [, int $cursor_type [, string $tag ] ] ) Eg ODBC_pconnect( $dns, $user,, $password, SQL_CUR_DEFAULT, Session_ID()+ 'LOG') The change of the PHP source of the function odbc_do_connect is minimal: void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) { char *db =3D NULL; char *uid =3D NULL; char *pwd =3D NULL; char *tag =3D NULL; zval **pv_db, **pv_uid, **pv_pwd, **pv_opt, **pv_tag; odbc_connection *db_conn; char *hashed_details; int hashed_len, cur_opt; /* Now an optional 4th parameter specifying the cursor type * defaulting to the cursors default */ switch(ZEND_NUM_ARGS()) { case 3:=09 if (zend_get_parameters_ex(3, &pv_db, &pv_uid, &pv_pwd) =3D=3D FAILURE) { WRONG_PARAM_COUNT; } /* Use Default: Probably a better way to do this */ cur_opt =3D SQL_CUR_DEFAULT; tag =3D ''; break; case 4: if (zend_get_parameters_ex(4, &pv_db, &pv_uid, &pv_pwd, &pv_opt) =3D=3D FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(pv_opt); cur_opt =3D Z_LVAL_PP(pv_opt); /* Confirm the cur_opt range */ if (! (cur_opt =3D=3D SQL_CUR_USE_IF_NEEDED ||=20 cur_opt =3D=3D SQL_CUR_USE_ODBC ||=20 cur_opt =3D=3D SQL_CUR_USE_DRIVER ||=20 cur_opt =3D=3D SQL_CUR_DEFAULT) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Cursor type (%d)", cur_opt); RETURN_FALSE; } tag =3D ''; break; case 5: if (zend_get_parameters_ex(5, &pv_db, &pv_uid, &pv_pwd, &pv_opt, &pv_tag) =3D=3D FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(pv_opt); cur_opt =3D Z_LVAL_PP(pv_opt); /* Confirm the cur_opt range */ if (! (cur_opt =3D=3D SQL_CUR_USE_IF_NEEDED ||=20 cur_opt =3D=3D SQL_CUR_USE_ODBC ||=20 cur_opt =3D=3D SQL_CUR_USE_DRIVER ||=20 cur_opt =3D=3D SQL_CUR_DEFAULT) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Cursor type (%d)", cur_opt); RETURN_FALSE; } convert_to_string_ex(pv_tag); tag =3D Z_STRVAL_PP(pv_tag); break; default: WRONG_PARAM_COUNT; break; } convert_to_string_ex(pv_db); convert_to_string_ex(pv_uid); convert_to_string_ex(pv_pwd); db =3D Z_STRVAL_PP(pv_db); uid =3D Z_STRVAL_PP(pv_uid); pwd =3D Z_STRVAL_PP(pv_pwd); if (ODBCG(allow_persistent) <=3D 0) { persistent =3D 0; } hashed_len =3D spprintf(&hashed_details, 0, "%s_%s_%s_%s_%d_%s", ODBC_TYPE, db, uid, pwd, cur_opt, tag); Gomar Bijl Software Engineer BU400 CAL Consult Phone +31 (0) 318 - 691 300 Fax +31 (0) 318 - 691 301 Direct +31 (0) 318 - 691 366 E-mail gomar.bijl@cal-consult.nl KvK nr. 09078710 ----------------------------------------------------------------------- Software for logistics www.cal-consult.nl =20 ----------------------------------------------------------------------- ------_=_NextPart_001_01C8D769.1199524A--