1--TEST-- 2mysqli_stmt_field_counts() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 require('table.inc'); 14 15 $stmt = mysqli_stmt_init($link); 16 17 try { 18 mysqli_stmt_field_count($stmt); 19 } catch (Error $exception) { 20 echo $exception->getMessage() . "\n"; 21 } 22 23 if (mysqli_stmt_prepare($stmt, '')) 24 printf("[004] Prepare should fail for an empty statement\n"); 25 26 try { 27 mysqli_stmt_field_count($stmt); 28 } catch (Error $exception) { 29 echo $exception->getMessage() . "\n"; 30 } 31 32 if (!mysqli_stmt_prepare($stmt, 'SELECT 1')) 33 printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 34 if (1 !== ($tmp = mysqli_stmt_field_count($stmt))) 35 printf("[007] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 36 37 if (!mysqli_stmt_prepare($stmt, 'SELECT 1, 2')) 38 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 39 if (2 !== ($tmp = mysqli_stmt_field_count($stmt))) 40 printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); 41 42 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test')) 43 printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 44 if (2 !== ($tmp = mysqli_stmt_field_count($stmt))) 45 printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); 46 47 if (!mysqli_stmt_prepare($stmt, 'SELECT label FROM test') || 48 !mysqli_stmt_execute($stmt)) 49 printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 50 if (1 !== ($tmp = mysqli_stmt_field_count($stmt))) 51 printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 52 53 $label = null; 54 try { 55 if (mysqli_stmt_bind_param($stmt, "s", $label)) 56 printf("[014] expected error - got ok\n"); 57 } catch (\ArgumentCountError $e) { 58 echo $e->getMessage() . \PHP_EOL; 59 } 60 while (mysqli_stmt_fetch($stmt)) 61 if (1 !== ($tmp = mysqli_stmt_field_count($stmt))) 62 printf("[015] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 63 64 if (!mysqli_stmt_prepare($stmt, 'INSERT INTO test(id) VALUES (100)')) 65 printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 66 if (0 !== ($tmp = mysqli_stmt_field_count($stmt))) 67 printf("[017] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 68 69 if (!mysqli_stmt_prepare($stmt, "UPDATE test SET label = 'z' WHERE id = 1") || 70 !mysqli_stmt_execute($stmt)) 71 printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 72 73 if (0 !== ($tmp = mysqli_stmt_field_count($stmt))) 74 printf("[019] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 75 76 mysqli_stmt_close($stmt); 77 78 try { 79 mysqli_stmt_prepare($stmt, 'SELECT id FROM test'); 80 } catch (Error $exception) { 81 echo $exception->getMessage() . "\n"; 82 } 83 84 try { 85 mysqli_stmt_field_count($stmt); 86 } catch (Error $exception) { 87 echo $exception->getMessage() . "\n"; 88 } 89 90 mysqli_close($link); 91 92 print "done!"; 93?> 94--CLEAN-- 95<?php 96 require_once("clean_table.inc"); 97?> 98--EXPECT-- 99mysqli_stmt object is not fully initialized 100mysqli_stmt object is not fully initialized 101The number of variables must match the number of parameters in the prepared statement 102mysqli_stmt object is already closed 103mysqli_stmt object is already closed 104done! 105