note 89329 deleted from mysqli-stmt.affected-rows by joey

From: Date: Thu, 12 Jan 2012 04:49:42 +0000
Subject: note 89329 deleted from mysqli-stmt.affected-rows by joey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185596@lists.php.net to get a copy of this message
Note Submitter: Senthryl ---- This property contains a -1 value in situations when no errors have occurred. When preparing a SELECT statement (or any other statement which doesn't affect rows), the property will be -1. The property will also be reset to -1 if an INSERT statement is re-prepared as a SELECT statement. For example: <?php $mysqli = new mysqli('localhost', 'user', 'pass', 'test'); $stmt = $mysqli->stmt_init(); $param = 'value'; //First SELECT $stmt->prepare('SELECT * FROM test WHERE field=?'); $stmt->bind_param('s', $param); var_dump($stmt->execute()); var_dump($stmt->affected_rows); echo '<br>'; //INSERT $stmt->prepare('INSERT INTO test (field) VALUES (?)'); $stmt->bind_param('s', $param); var_dump($stmt->execute()); var_dump($stmt->affected_rows); echo '<br>'; //Second SELECT $stmt->prepare('SELECT * FROM test WHERE field=?'); $stmt->bind_param('s', $param); var_dump($stmt->execute()); var_dump($stmt->affected_rows); echo '<br>'; ?> Displays: bool(true) int(-1) bool(true) int(1) bool(true) int(-1)

« previous php.notes (#185596) next »