查询就像那样简单:
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 ms才能执行:
最好的问候,Duluman Edi
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上托管这个。
答案 0 :(得分:0)
我想我可以对$(document).ready()进行ajax调用,以便在页面加载后进行此更改,因为此UPDATE语句已完全嵌套。
答案 1 :(得分:0)
您能否确保id
列是index
?或primary key
...这将使您的查询快速点亮。
CREATE UNIQUE INDEX uid ON users