@@ -1307,6 +1307,7 @@ PHP_FUNCTION(odbc_exec)
13071307/* }}} */
13081308
13091309typedef enum php_odbc_fetch_result_type_t {
1310+ ODBC_NONE = 0 ,
13101311 ODBC_NUM = 1 ,
13111312 ODBC_OBJECT = 2 ,
13121313} php_odbc_fetch_result_type_t ;
@@ -1323,7 +1324,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
13231324 bool pv_row_is_null = true;
13241325 zval * pv_res , * pv_res_arr , tmp ;
13251326
1326- if (return_array ) {
1327+ if (return_array || result_type == ODBC_NONE ) {
13271328 ZEND_PARSE_PARAMETERS_START (1 , 2 )
13281329 Z_PARAM_OBJECT_OF_CLASS (pv_res , odbc_result_ce )
13291330 Z_PARAM_OPTIONAL
@@ -1343,7 +1344,13 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
13431344 result = Z_ODBC_RESULT_P (pv_res );
13441345 CHECK_ODBC_RESULT (result );
13451346
1346- /* TODO deprecate $row argument values less than 1 after PHP 8.4 */
1347+ /* TODO deprecate $row argument values less than 1 after PHP 8.4
1348+ * for functions other than odbc_fetch_row (see GH-13910)
1349+ */
1350+ if (!result_type && !pv_row_is_null && pv_row < 1 ) {
1351+ php_error_docref (NULL , E_WARNING , "Argument #3 ($row) must be greater than or equal to 1" );
1352+ RETURN_FALSE ;
1353+ }
13471354
13481355 if (result -> numcols == 0 ) {
13491356 php_error_docref (NULL , E_WARNING , "No tuples available at this result index" );
@@ -1353,7 +1360,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
13531360 /* If we're initializing a passed value into an array, do it before the fetch
13541361 * so that an empty result set will still be an array.
13551362 */
1356- if (!return_array ) {
1363+ if (!return_array && result_type ) {
13571364 pv_res_arr = zend_try_array_init (pv_res_arr );
13581365 if (!pv_res_arr ) {
13591366 RETURN_THROWS ();
@@ -1378,7 +1385,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
13781385 }
13791386
13801387 /* ...but if returning an array, init only if we have a result set */
1381- if (return_array ) {
1388+ if (return_array && result_type ) {
13821389 array_init (pv_res_arr );
13831390 }
13841391
@@ -1387,6 +1394,13 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
13871394 else
13881395 result -> fetched ++ ;
13891396
1397+ /* For fetch_row, we don't return anything other than true,
1398+ * odbc_result will be used to fetch values instead.
1399+ */
1400+ if (result_type == ODBC_NONE ) {
1401+ RETURN_TRUE ;
1402+ }
1403+
13901404 for (i = 0 ; i < result -> numcols ; i ++ ) {
13911405 sql_c_type = SQL_C_CHAR ;
13921406
@@ -1503,53 +1517,7 @@ PHP_FUNCTION(odbc_fetch_into)
15031517/* {{{ Fetch a row */
15041518PHP_FUNCTION (odbc_fetch_row )
15051519{
1506- odbc_result * result ;
1507- RETCODE rc ;
1508- zval * pv_res ;
1509- zend_long pv_row = 0 ;
1510- bool pv_row_is_null = true;
1511-
1512- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|l!" , & pv_res , odbc_result_ce , & pv_row , & pv_row_is_null ) == FAILURE ) {
1513- RETURN_THROWS ();
1514- }
1515-
1516- result = Z_ODBC_RESULT_P (pv_res );
1517- CHECK_ODBC_RESULT (result );
1518-
1519- if (!pv_row_is_null && pv_row < 1 ) {
1520- php_error_docref (NULL , E_WARNING , "Argument #3 ($row) must be greater than or equal to 1" );
1521- RETURN_FALSE ;
1522- }
1523-
1524- if (result -> numcols == 0 ) {
1525- php_error_docref (NULL , E_WARNING , "No tuples available at this result index" );
1526- RETURN_FALSE ;
1527- }
1528-
1529- if (result -> fetch_abs ) {
1530- if (!pv_row_is_null ) {
1531- rc = SQLFetchScroll (result -> stmt , SQL_FETCH_ABSOLUTE , (SQLLEN )pv_row );
1532- } else {
1533- rc = SQLFetchScroll (result -> stmt , SQL_FETCH_NEXT , 1 );
1534- }
1535- } else {
1536- rc = SQLFetch (result -> stmt );
1537- }
1538-
1539- if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
1540- if (rc == SQL_ERROR ) {
1541- odbc_sql_error (result -> conn_ptr , result -> stmt , "SQLFetchScroll" );
1542- }
1543- RETURN_FALSE ;
1544- }
1545-
1546- if (!pv_row_is_null ) {
1547- result -> fetched = (SQLLEN )pv_row ;
1548- } else {
1549- result -> fetched ++ ;
1550- }
1551-
1552- RETURN_TRUE ;
1520+ php_odbc_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , false, ODBC_NONE );
15531521}
15541522/* }}} */
15551523
0 commit comments