查询就是这么简单:
Eg 1: "UPDATE threads SET hits = hits+1 WHERE id = TID"
Eg 2: "UPDATE users SET last_activity = unix_timestamp() WHERE id = UID"
`users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`last_activity` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
`threads` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`hits` int(10) unsigned NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci让我们以这个查询为例:
mysql_query("UPDATE users SET last_activity = unix_timestamp() WHERE id = UID");在没有查询的情况下,执行脚本需要大约30毫秒:

对于查询,脚本需要大约110毫秒来执行:

致以最好的问候,杜鲁曼·埃迪
LE:生成执行时间的代码如下:
///this is placed above any code
$mtime = explode(' ',microtime());
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
.....
my game code is here
.....
$mtime = explode(' ',microtime());
echo lang('info','page_load').' '.number_format(($mtime[1] + $mtime[0]) - $tstart,4,'.','')*1000; 这就是我计算执行时间的方法,它非常准确,从未让我失望过。附注-实际执行时间减少了大约15毫秒,因为我目前在Windows上托管此程序。
发布于 2012-06-09 18:58:33
我猜我可以在$(document).ready()上进行ajax调用,以便在页面加载后进行此更改,因为此UPDATE语句非常嵌套。
发布于 2015-03-06 22:09:36
您能确保您的id列是一个index吗?或者primary key..。这将使您的查询照明更快。
CREATE UNIQUE INDEX uid ON usershttps://stackoverflow.com/questions/10960208
复制相似问题