@@ -102,7 +102,7 @@ static int _close_pconn_with_res(zval *zv, void *p)
102
102
}
103
103
104
104
odbc_connection * list_conn = ((odbc_connection * )(le -> ptr ));
105
- odbc_connection * obj_conn = odbc_link_from_obj (( zend_object * ) p ) -> connection ;
105
+ odbc_connection * obj_conn = ( odbc_connection * ) p ;
106
106
if (list_conn == obj_conn ) {
107
107
return ZEND_HASH_APPLY_REMOVE ;
108
108
}
@@ -138,10 +138,10 @@ static void odbc_link_free(odbc_link *link)
138
138
zend_hash_destroy (& link -> connection -> results );
139
139
efree (link -> connection );
140
140
ODBCG (num_links )-- ;
141
+ }
141
142
142
- if (link -> hash ) {
143
- zend_hash_del (& ODBCG (non_persistent_connections ), link -> hash );
144
- }
143
+ if (link -> hash ) {
144
+ zend_hash_del (& ODBCG (connections ), link -> hash );
145
145
}
146
146
147
147
link -> connection = NULL ;
@@ -317,6 +317,7 @@ static void _close_odbc_pconn(zend_resource *rsrc)
317
317
SQLFreeConnect (conn -> hdbc );
318
318
SQLFreeEnv (conn -> henv );
319
319
}
320
+ free (conn );
320
321
321
322
ODBCG (num_links )-- ;
322
323
ODBCG (num_persistent )-- ;
@@ -501,12 +502,12 @@ static PHP_GINIT_FUNCTION(odbc)
501
502
ZEND_TSRMLS_CACHE_UPDATE ();
502
503
#endif
503
504
odbc_globals -> num_persistent = 0 ;
504
- zend_hash_init (& odbc_globals -> non_persistent_connections , 0 , NULL , NULL , 1 );
505
+ zend_hash_init (& odbc_globals -> connections , 0 , NULL , NULL , 1 );
505
506
}
506
507
507
508
static PHP_GSHUTDOWN_FUNCTION (odbc )
508
509
{
509
- zend_hash_destroy (& odbc_globals -> non_persistent_connections );
510
+ zend_hash_destroy (& odbc_globals -> connections );
510
511
}
511
512
512
513
/* {{{ PHP_MINIT_FUNCTION */
@@ -878,14 +879,14 @@ PHP_FUNCTION(odbc_close_all)
878
879
}
879
880
880
881
/* Loop through the non-persistent connection list, now close all non-persistent connections and their results */
881
- ZEND_HASH_FOREACH_VAL (& ODBCG (non_persistent_connections ), zv ) {
882
+ ZEND_HASH_FOREACH_VAL (& ODBCG (connections ), zv ) {
882
883
odbc_link * link = Z_ODBC_LINK_P (zv );
883
884
if (link -> connection ) {
884
885
odbc_link_free (link );
885
886
}
886
887
} ZEND_HASH_FOREACH_END ();
887
888
888
- zend_hash_clean (& ODBCG (non_persistent_connections ));
889
+ zend_hash_clean (& ODBCG (connections ));
889
890
890
891
zend_hash_apply (& EG (persistent_list ), _close_pconn );
891
892
}
@@ -2299,7 +2300,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2299
2300
}
2300
2301
2301
2302
char * hashed_details ;
2302
- int hashed_details_len = spprintf (& hashed_details , 0 , "%s_%s_%s_%s_%d" , ODBC_TYPE , db , uid , pwd , cur_opt );
2303
+ int hashed_details_len = spprintf (& hashed_details , 0 , "%d_% s_%s_%s_%s_%d" , persistent , ODBC_TYPE , db , uid , pwd , cur_opt );
2303
2304
2304
2305
try_and_get_another_connection :
2305
2306
@@ -2333,6 +2334,8 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2333
2334
RETURN_FALSE ;
2334
2335
}
2335
2336
2337
+ zend_hash_str_add_new (& ODBCG (connections ), hashed_details , hashed_details_len , return_value );
2338
+
2336
2339
ODBCG (num_persistent )++ ;
2337
2340
ODBCG (num_links )++ ;
2338
2341
} else { /* found connection */
@@ -2381,15 +2384,22 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2381
2384
}
2382
2385
}
2383
2386
2384
- object_init_ex (return_value , odbc_connection_ce );
2385
- odbc_link * link = Z_ODBC_LINK_P (return_value );
2386
- link -> connection = db_conn ;
2387
- link -> hash = zend_string_init (hashed_details , hashed_details_len , persistent );
2388
- link -> persistent = true;
2387
+ zval * tmp ;
2388
+ if ((tmp = zend_hash_str_find (& ODBCG (connections ), hashed_details , hashed_details_len )) == NULL ) {
2389
+ object_init_ex (return_value , odbc_connection_ce );
2390
+ odbc_link * link = Z_ODBC_LINK_P (return_value );
2391
+ link -> connection = db_conn ;
2392
+ link -> hash = zend_string_init (hashed_details , hashed_details_len , persistent );
2393
+ link -> persistent = true;
2394
+ } else {
2395
+ ZVAL_COPY (return_value , tmp );
2396
+
2397
+ ZEND_ASSERT (Z_ODBC_CONNECTION_P (return_value ) == db_conn && "Persistent connection has changed" );
2398
+ }
2389
2399
}
2390
- } else {
2400
+ } else { /* non-persistent */
2391
2401
zval * tmp ;
2392
- if ((tmp = zend_hash_str_find (& ODBCG (non_persistent_connections ), hashed_details , hashed_details_len )) == NULL ) { /* non-persistent, new */
2402
+ if ((tmp = zend_hash_str_find (& ODBCG (connections ), hashed_details , hashed_details_len )) == NULL ) { /* non-persistent, new */
2393
2403
if (ODBCG (max_links ) != -1 && ODBCG (num_links ) >= ODBCG (max_links )) {
2394
2404
php_error_docref (NULL , E_WARNING , "Too many open connections (" ZEND_LONG_FMT ")" , ODBCG (num_links ));
2395
2405
efree (hashed_details );
@@ -2403,7 +2413,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2403
2413
}
2404
2414
ODBCG (num_links )++ ;
2405
2415
2406
- zend_hash_str_add_new (& ODBCG (non_persistent_connections ), hashed_details , hashed_details_len , return_value );
2416
+ zend_hash_str_add_new (& ODBCG (connections ), hashed_details , hashed_details_len , return_value );
2407
2417
} else { /* non-persistent, pre-existing */
2408
2418
ZVAL_COPY (return_value , tmp );
2409
2419
}
@@ -2417,19 +2427,21 @@ PHP_FUNCTION(odbc_close)
2417
2427
{
2418
2428
zval * pv_conn ;
2419
2429
odbc_link * link ;
2430
+ odbc_connection * connection ;
2420
2431
2421
2432
if (zend_parse_parameters (ZEND_NUM_ARGS (), "O" , & pv_conn , odbc_connection_ce ) == FAILURE ) {
2422
2433
RETURN_THROWS ();
2423
2434
}
2424
2435
2425
2436
link = Z_ODBC_LINK_P (pv_conn );
2426
- CHECK_ODBC_CONNECTION (link -> connection );
2437
+ connection = Z_ODBC_CONNECTION_P (pv_conn );
2438
+ CHECK_ODBC_CONNECTION (connection );
2439
+
2440
+ odbc_link_free (link );
2427
2441
2428
2442
if (link -> persistent ) {
2429
- zend_hash_apply_with_argument (& EG (persistent_list ), _close_pconn_with_res , (void * ) Z_OBJ_P ( pv_conn ) );
2443
+ zend_hash_apply_with_argument (& EG (persistent_list ), _close_pconn_with_res , (void * ) connection );
2430
2444
}
2431
-
2432
- odbc_link_free (link );
2433
2445
}
2434
2446
/* }}} */
2435
2447
0 commit comments