1--TEST-- 2mysqli_fetch_assoc() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $tmp = NULL; 14 $link = NULL; 15 16 // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test 17 $mysqli = new mysqli(); 18 $res = @new mysqli_result($mysqli); 19 if (false !== ($tmp = @$res->fetch_assoc())) 20 printf("[001] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 21 22 require('table.inc'); 23 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 24 printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 25 $host, $user, $db, $port, $socket); 26 27 if (!is_null($tmp = @$res->fetch_assoc($link))) 28 printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 29 30 if (!$res = $mysqli->query("SELECT id, label FROM test ORDER BY id LIMIT 1")) { 31 printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); 32 } 33 34 print "[005]\n"; 35 var_dump($res->fetch_assoc()); 36 37 print "[006]\n"; 38 var_dump($res->fetch_assoc()); 39 40 $res->free_result(); 41 42 if (!$res = $mysqli->query("SELECT 1 AS a, 2 AS a, 3 AS c, 4 AS C, NULL AS d, true AS e")) { 43 printf("[007] Cannot run query, [%d] %s\n", $mysqli->errno, $mysqli->error); 44 } 45 print "[008]\n"; 46 var_dump($res->fetch_assoc()); 47 48 $res->free_result(); 49 50 if (false !== ($tmp = $res->fetch_assoc())) 51 printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 52 53 mysqli_close($link); 54 55 print "done!"; 56?> 57--CLEAN-- 58<?php 59 require_once("clean_table.inc"); 60?> 61--EXPECTF-- 62[005] 63array(2) { 64 ["id"]=> 65 string(1) "1" 66 ["label"]=> 67 string(1) "a" 68} 69[006] 70NULL 71[008] 72array(5) { 73 ["a"]=> 74 string(1) "2" 75 ["c"]=> 76 string(1) "3" 77 ["C"]=> 78 string(1) "4" 79 ["d"]=> 80 NULL 81 ["e"]=> 82 string(1) "1" 83} 84 85Warning: mysqli_result::fetch_assoc(): Couldn't fetch mysqli_result in %s on line %d 86done! 87