note 89329 added to mysqli-stmt.affected-rows
| From: | Senthryl at osu1 dot php dot net | Date: | Tue, 03 Mar 2009 19:11:41 +0000 |
| Subject: | note 89329 added to mysqli-stmt.affected-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151410@lists.php.net to get a copy of this message | ||
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)
----
Server IP: 66.207.199.35
Probable Submitter: 209.159.189.12
----
Manual Page -- http://www.php.net/manual/en/mysqli-stmt.affected-rows.php
Edit -- https://master.php.net/note/edit/89329
Del: integrated -- https://master.php.net/note/delete/89329/integrated
Del: useless -- https://master.php.net/note/delete/89329/useless
Del: bad code -- https://master.php.net/note/delete/89329/bad+code
Del: spam -- https://master.php.net/note/delete/89329/spam
Del: non-english -- https://master.php.net/note/delete/89329/non-english
Del: in docs -- https://master.php.net/note/delete/89329/in+docs
Del: other reasons-- https://master.php.net/note/delete/89329
Reject -- https://master.php.net/note/reject/89329
Search -- https://master.php.net/manage/user-notes.php