rows-affected

Codeigniter db->update() VS MySQL native UPDATE Affected rows: 0

℡╲_俬逩灬. 提交于 2019-12-31 02:01:46
问题 Using MySQL alone - If I make a basic update to a table like this: UPDATE `SOMETABLE` SET `NAME` = 'John' WHERE `ID` = 1; And the value of NAME = ' John ' was already ' John ' - in other-words - nothing is new, nothing to update. MySQL returns " Affected rows: 0 (Query took 0.0007 sec) " If I make the same call - now using CodeIgniter - and then retrieve the affected rows like this: $data = array( 'NAME' => 'John' ); $this->db->where('ID', 1); $this->db->update('SOMETABLE', $data); $affect =

UPDATE/DELETE in mysql and get the list of affected row ids?

Deadly 提交于 2019-12-28 13:31:32
问题 Is there an efficient way to get the list of affected row IDs (not the # of affected rows via PHP's mysql_affected_rows(), but the actual row ids that were affected) from an UPDATE or DELETE query in mysql? In postgresql, there is a RETURNING clause within UPDATE/DELETE queries that can be used to specify values from the affected rows that are returned. In mysql, the 'brute force' way of getting the affected rows seem to be: 1. Acquire READ LOCK. 2. SELECT to with the WHERE condition of the

UPDATE/DELETE in mysql and get the list of affected row ids?

此生再无相见时 提交于 2019-12-28 13:31:24
问题 Is there an efficient way to get the list of affected row IDs (not the # of affected rows via PHP's mysql_affected_rows(), but the actual row ids that were affected) from an UPDATE or DELETE query in mysql? In postgresql, there is a RETURNING clause within UPDATE/DELETE queries that can be used to specify values from the affected rows that are returned. In mysql, the 'brute force' way of getting the affected rows seem to be: 1. Acquire READ LOCK. 2. SELECT to with the WHERE condition of the

Differentiate between 'no rows were affected' and rows succesfully UPDATEd--to same value (MySQL and PHP)

谁说胖子不能爱 提交于 2019-12-24 03:25:36
问题 I am executing SQL (MySQL) commands from PHP. There are several possible outcomes to each execution: Record updated to new value Record updated, but values happen to be the same Record finds no rows to update (ie, no rows match the WHERE clause) I am wondering how to differentiate between #'s 1 and 3: both cases return zero as the number of rows being affected, so: $result = $db->exec($statement) will have $result == 0 in both cases. How can I tell the difference? EDIT: I meant to ask how to

How to determine if a MySQL update query succeeded when the data passed in the query is the same as what is already in the database?

孤人 提交于 2019-12-21 08:00:13
问题 Let's say you have a form with pre-populated data from your database, and you allow your users to make changes and save the form. If the user clicks the save button without making any changes, MySQL will not actually perform a write operation, and therefore the affected_rows will return 0. I understand the behavior, but what is the best practice for determining if an update failed, other than checking for the number of affected_rows? What is the best practice for differentiating between an

How to determine if a MySQL update query succeeded when the data passed in the query is the same as what is already in the database?

蹲街弑〆低调 提交于 2019-12-04 03:07:28
Let's say you have a form with pre-populated data from your database, and you allow your users to make changes and save the form. If the user clicks the save button without making any changes, MySQL will not actually perform a write operation, and therefore the affected_rows will return 0. I understand the behavior, but what is the best practice for determining if an update failed, other than checking for the number of affected_rows? What is the best practice for differentiating between an update that actually failed, and one that "succeeded" but resulted in 0 affected_rows so that I can

Codeigniter db->update() VS MySQL native UPDATE Affected rows: 0

扶醉桌前 提交于 2019-12-01 20:46:37
Using MySQL alone - If I make a basic update to a table like this: UPDATE `SOMETABLE` SET `NAME` = 'John' WHERE `ID` = 1; And the value of NAME = ' John ' was already ' John ' - in other-words - nothing is new, nothing to update. MySQL returns " Affected rows: 0 (Query took 0.0007 sec) " If I make the same call - now using CodeIgniter - and then retrieve the affected rows like this: $data = array( 'NAME' => 'John' ); $this->db->where('ID', 1); $this->db->update('SOMETABLE', $data); $affect = $this->db->affected_rows(); echo $affect; // $affect echos 1 $affect ends up equaling 1. I haven't got

Netbeans Xdebug: mysqli_affected_rows returns “-1” when it should be “1”

余生颓废 提交于 2019-12-01 07:22:57
问题 I'm puzzled why the following code successfully adds a new row to my database table while mysqli_affected_rows($dbc) returns "-1", thus an error, in signup.php: dbc.inc.php : DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', ''); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'v'); $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); mysqli_set_charset($dbc, 'utf8'); signup.php : require('dbc.inc.php'); //code to set variables for

MySQL get all affected rows for multiple statements in one query

纵饮孤独 提交于 2019-11-29 12:44:05
MySQL/PHP: For a query with multiple statements, which deletes rows in four different tables, I want to know the combined number of affected rows. The PHP manual says I'll only get the result from the last 'operation', which suggests it will only tell me how many rows were affected by the last of the DELETE statements. How to get around this? $deleteContactSQL = "DELETE FROM `persons` WHERE `persons`.`id` = '$person' AND `owner = '$user' AND `userOrContact` = 'contact'; DELETE FROM `tabs` WHERE `person` = '$person' AND `ownerIdentity` = '$user' AND `selfOrOther` = 'other'; DELETE FROM

MySQL get all affected rows for multiple statements in one query

你离开我真会死。 提交于 2019-11-28 06:38:34
问题 MySQL/PHP: For a query with multiple statements, which deletes rows in four different tables, I want to know the combined number of affected rows. The PHP manual says I'll only get the result from the last 'operation', which suggests it will only tell me how many rows were affected by the last of the DELETE statements. How to get around this? $deleteContactSQL = "DELETE FROM `persons` WHERE `persons`.`id` = '$person' AND `owner = '$user' AND `userOrContact` = 'contact'; DELETE FROM `tabs`