note 118435 added to mysqli.affected-rows

From: Date: Fri, 04 Dec 2015 22:48:09 +0000
Subject: note 118435 added to mysqli.affected-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-204285@lists.php.net to get a copy of this message
This may seem obvious, but if you do an UPDATE with each of the values in your SET clause having the exact same value that is already in the table, then affected_rows returns 0. For example: <?php $mysqli = new mysqli($host, $usr, $pwd, $db, $port); $appointment_date = "2015-12-07"; $sql = "update appointments set appointment_date = ? where appointment_id = 78"; $stmt = $mysqli->prepare($sql); $stmt->bind_param("s",$appointment_date); $stmt->execute(); echo $mysqli ->affected_rows . "<br>"; ?> This returns 1 the first time I run it after changing the value of the $appointment_date variable. When I run it a second time (making no changes), it returns 0. I also verified the same behavior without using prepared statements. ---- Server IP: 72.52.91.14 Probable Submitter: 24.55.129.80 ---- Manual Page -- http://php.net/manual/en/mysqli.affected-rows.php Edit -- https://master.php.net/note/edit/118435 Del: integrated -- https://master.php.net/note/delete/118435/integrated Del: useless -- https://master.php.net/note/delete/118435/useless Del: bad code -- https://master.php.net/note/delete/118435/bad+code Del: spam -- https://master.php.net/note/delete/118435/spam Del: non-english -- https://master.php.net/note/delete/118435/non-english Del: in docs -- https://master.php.net/note/delete/118435/in+docs Del: other reasons-- https://master.php.net/note/delete/118435 Reject -- https://master.php.net/note/reject/118435 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204285) next »