REPLACE INTO 为什么返回”2 rows affected”
表的结构:
desc urls;
+――-+―――――――+――+―-+―――+――-+
| Field | Type | Null | Key | Default | Extra |
+――-+―――――――+――+―-+―――+――-+
| id | bigint(16) unsigned | NO | PRI | NULL | |
| url | varchar(255) | NO | | NULL | |
| md516 | varchar(32) | NO | UNI | | |
+――-+―――――――+――+―-+―――+――-+
3 rows in set (0.01 sec)
原有数据:
+―-+―――――――-+――――――+
| id | url | md516 |
+―-+―――――――-+――――――+
| 0 | http://www.162cm.com/ | 49f6f2aaa26c124a |
+―-+―――――――-+――――――+
1 row in set (0.00 sec)
执行的语句:
REPLACE INTO urls (`url`,`md516`,`id`) VALUES (’http://www.162cm.com/’,\'49f6f2aaa26c124a’,0);
而执行这条语句的返回是:
Query OK, 2 rows affected (0.00 sec)
为啥呢….看起来数据啥也没变,不是吗?
看文档:http://au2.php.net/mysql_affected_rows:
Returns the number of affected rows on success, and -1 if the last query failed.
If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2.
When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.
The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records.
建议继续学习:
- window.location.href,window.location.replace(),window.location.reload() 三者的区别 (阅读:4214)
- substr、replace函数简单应用 (阅读:3720)
- href,replace(),reload() 三者的区别 (阅读:3379)
- javascript的String.replace的妙用 (阅读:2742)
扫一扫订阅我的微信号:IT技术博客大学习
- 作者:互联网,请记住我 来源: 互联网,请记住我
- 标签: replace
- 发布时间:2009-10-16 12:13:22
-
[917] WordPress插件开发 -- 在插件使用 -
[135] 解决 nginx 反向代理网页首尾出现神秘字 -
[54] 整理了一份招PHP高级工程师的面试题 -
[52] Innodb分表太多或者表分区太多,会导致内 -
[52] 海量小文件存储 -
[52] 如何保证一个程序在单台服务器上只有唯一实例( -
[51] 全站换域名时利用nginx和javascri -
[50] 用 Jquery 模拟 select -
[49] CloudSMS:免费匿名的云短信 -
[48] jQuery性能优化指南
