1--TEST-- 2mysqli->affected_rows 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7 require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $mysqli = new mysqli(); 14 try { 15 $mysqli->affected_rows; 16 } catch (Error $exception) { 17 echo $exception->getMessage() . "\n"; 18 } 19 20 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) { 21 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 22 $host, $user, $db, $port, $socket); 23 } 24 25 if (0 !== ($tmp = $mysqli->affected_rows)) 26 printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 27 28 if (!$mysqli->query('DROP TABLE IF EXISTS test')) 29 printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); 30 31 if (!$mysqli->query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine)) 32 printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); 33 34 if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')")) 35 printf("[005] [%d] %s\n", $mysqli->errno, $mysqli->error); 36 37 if (1 !== ($tmp = $mysqli->affected_rows)) 38 printf("[006] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 39 40 // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented 41 $mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')"); 42 if (-1 !== ($tmp = $mysqli->affected_rows)) 43 printf("[007] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp); 44 45 if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4")) 46 printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); 47 48 if (2 !== ($tmp = $mysqli->affected_rows)) 49 printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); 50 51 if (!$mysqli->query("INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')")) 52 printf("[010] [%d] %s\n", $mysqli->errno, $mysqli->error); 53 54 if (2 !== ($tmp = $mysqli->affected_rows)) 55 printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); 56 57 if (!$mysqli->query("INSERT IGNORE INTO test(id, label) VALUES (1, 'a')")) { 58 printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error); 59 } 60 61 if (1 !== ($tmp = $mysqli->affected_rows)) 62 printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 63 64 if (!$mysqli->query("INSERT INTO test(id, label) SELECT id + 10, label FROM test")) 65 printf("[014] [%d] %s\n", $mysqli->errno, $mysqli->error); 66 67 if (4 !== ($tmp = $mysqli->affected_rows)) 68 printf("[015] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp); 69 70 if (!$mysqli->query("REPLACE INTO test(id, label) values (4, 'd')")) 71 printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error); 72 73 if (2 !== ($tmp = $mysqli->affected_rows)) 74 printf("[016] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); 75 76 if (!$mysqli->query("REPLACE INTO test(id, label) values (5, 'e')")) 77 printf("[017] [%d] %s\n", $mysqli->errno, $mysqli->error); 78 79 if (1 !== ($tmp = $mysqli->affected_rows)) 80 printf("[018] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 81 82 if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2")) 83 printf("[019] [%d] %s\n", $mysqli->errno, $mysqli->error); 84 85 if (1 !== ($tmp = $mysqli->affected_rows)) 86 printf("[020] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); 87 88 if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2")) { 89 printf("[021] [%d] %s\n", $mysqli->errno, $mysqli->error); 90 } 91 92 if (0 !== ($tmp = $mysqli->affected_rows)) 93 printf("[022] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 94 95 if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 100")) { 96 printf("[023] [%d] %s\n", $mysqli->errno, $mysqli->error); 97 } 98 99 if (0 !== ($tmp = $mysqli->affected_rows)) 100 printf("[024] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 101 102 if (!$mysqli->query('DROP TABLE IF EXISTS test')) 103 printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error); 104 105 $mysqli->close(); 106 107 try { 108 $mysqli->affected_rows; 109 } catch (Error $exception) { 110 echo $exception->getMessage() . "\n"; 111 } 112 113 print "done!"; 114?> 115--CLEAN-- 116<?php 117 require_once("clean_table.inc"); 118?> 119--EXPECT-- 120Property access is not allowed yet 121Property access is not allowed yet 122done! 123