Skip to content

Commit

Permalink
Fix mysqli_stmt_get_result.phpt (php#15495)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela authored Aug 20, 2024
1 parent 660a860 commit 69d9c12
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions ext/mysqli/tests/mysqli_stmt_get_result.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ require_once 'skipifconnectfailure.inc';
if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

// FIXME - different versions return different values ?!
if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp))
printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
printf("[006] Expecting boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, true));

if (!mysqli_stmt_execute($stmt))
printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
Expand All @@ -39,7 +38,7 @@ require_once 'skipifconnectfailure.inc';
printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

if (is_object($tmp = mysqli_stmt_store_result($stmt)))
printf("[009] non-object, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
printf("[009] non-object, got %s/%s\n", gettype($tmp), var_export($tmp, true));

mysqli_stmt_close($stmt);

Expand All @@ -56,15 +55,14 @@ require_once 'skipifconnectfailure.inc';
if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

// FIXME - different versions return different values ?!
if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp))
printf("[013] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
printf("[013] Expecting boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, true));

if (!mysqli_stmt_execute($stmt))
printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

if (!is_object($tmp = mysqli_stmt_get_result($stmt)))
printf("[016] NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
if (! ($tmp = mysqli_stmt_get_result($stmt)) instanceof mysqli_result)
printf("[016] Expecting mysqli_result, got %s/%s\n", gettype($tmp), var_export($tmp, true));

mysqli_free_result($tmp);
mysqli_stmt_close($stmt);
Expand All @@ -83,25 +81,25 @@ require_once 'skipifconnectfailure.inc';
printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
printf("[020] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
printf("[020] Expecting boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, true));

if (!mysqli_stmt_execute($stmt))
printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

if (!is_object($tmp = mysqli_stmt_get_result($stmt)))
printf("[024] Expecting object, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
if (! ($tmp = mysqli_stmt_get_result($stmt)) instanceof mysqli_result)
printf("[024] Expecting mysqli_result, got %s/%s\n", gettype($tmp), var_export($tmp, true));

if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
printf("[025] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
printf("[025] false, got %s/%s\n", gettype($tmp), var_export($tmp, true));

if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label))) {
printf("[026] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
printf("[027] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link));
printf("[028] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
printf("[028] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, true));
}

if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
printf("[029] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
printf("[029] false, got %s/%s\n", gettype($tmp), var_export($tmp, true));

mysqli_stmt_close($stmt);

Expand Down Expand Up @@ -135,11 +133,11 @@ require_once 'skipifconnectfailure.inc';
$id = NULL;
$label = NULL;
if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
printf("[037] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
printf("[037] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, true));

if (!is_object($tmp = $result = mysqli_stmt_get_result($stmt)))
printf("[038] Expecting array, got %s/%s, [%d] %s\n",
gettype($tmp), var_export($tmp, 1),
if (! ($result = mysqli_stmt_get_result($stmt)) instanceof mysqli_result)
printf("[038] Expecting mysqli_result, got %s/%s, [%d] %s\n",
gettype($result), var_export($result, true),
mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));

if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
Expand All @@ -155,23 +153,23 @@ require_once 'skipifconnectfailure.inc';

$link->real_query('KILL '.mysqli_thread_id($link));
// We kill our own connection so we should get "Query execution was interrupted"
if ($link->errno !== 1317)
printf("[042] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if ($link->errno !== 1317)
printf("[042] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
printf("[043] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
printf("[043] Expecting boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, true));

mysqli_stmt_close($stmt);
mysqli_stmt_close($stmt);

try {
try {
mysqli_stmt_fetch($stmt);
} catch (Error $exception) {
echo $exception->getMessage(), "\n";
}

mysqli_close($link);
mysqli_close($link);

print "done!";
print "done!";
?>
--CLEAN--
<?php
Expand Down

0 comments on commit 69d9c12

Please sign in to comment.