@@ -1307,6 +1307,7 @@ PHP_FUNCTION(odbc_exec)
1307
1307
/* }}} */
1308
1308
1309
1309
typedef enum php_odbc_fetch_result_type_t {
1310
+ ODBC_NONE = 0 ,
1310
1311
ODBC_NUM = 1 ,
1311
1312
ODBC_OBJECT = 2 ,
1312
1313
} php_odbc_fetch_result_type_t ;
@@ -1323,7 +1324,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
1323
1324
bool pv_row_is_null = true;
1324
1325
zval * pv_res , * pv_res_arr , tmp ;
1325
1326
1326
- if (return_array ) {
1327
+ if (return_array || result_type == ODBC_NONE ) {
1327
1328
ZEND_PARSE_PARAMETERS_START (1 , 2 )
1328
1329
Z_PARAM_OBJECT_OF_CLASS (pv_res , odbc_result_ce )
1329
1330
Z_PARAM_OPTIONAL
@@ -1343,7 +1344,13 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
1343
1344
result = Z_ODBC_RESULT_P (pv_res );
1344
1345
CHECK_ODBC_RESULT (result );
1345
1346
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
+ }
1347
1354
1348
1355
if (result -> numcols == 0 ) {
1349
1356
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,
1353
1360
/* If we're initializing a passed value into an array, do it before the fetch
1354
1361
* so that an empty result set will still be an array.
1355
1362
*/
1356
- if (!return_array ) {
1363
+ if (!return_array && result_type ) {
1357
1364
pv_res_arr = zend_try_array_init (pv_res_arr );
1358
1365
if (!pv_res_arr ) {
1359
1366
RETURN_THROWS ();
@@ -1378,7 +1385,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
1378
1385
}
1379
1386
1380
1387
/* ...but if returning an array, init only if we have a result set */
1381
- if (return_array ) {
1388
+ if (return_array && result_type ) {
1382
1389
array_init (pv_res_arr );
1383
1390
}
1384
1391
@@ -1387,6 +1394,13 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, bool return_array,
1387
1394
else
1388
1395
result -> fetched ++ ;
1389
1396
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
+
1390
1404
for (i = 0 ; i < result -> numcols ; i ++ ) {
1391
1405
sql_c_type = SQL_C_CHAR ;
1392
1406
@@ -1503,53 +1517,7 @@ PHP_FUNCTION(odbc_fetch_into)
1503
1517
/* {{{ Fetch a row */
1504
1518
PHP_FUNCTION (odbc_fetch_row )
1505
1519
{
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 );
1553
1521
}
1554
1522
/* }}} */
1555
1523
0 commit comments