1.testデータベースにtest_tableテーブルを作成。
2.1万件のデータを登録します。
3.1000件のフラグを更新
4.更新したデータを検索する時刻を測定して表示
するサンプルです。
<?php
/* B接続 */
$con = mysql_connect("localhost","root","pass");
if (!$con)
{
echo mysql_error();
}
/* DB選択 */
mysql_select_db("test", $con);
/* テーブル作成 */
$sql="DROP TABLE IF EXISTS `test`.`test_table`;";
if(!mysql_query($sql)){
echo "sql=[".$sql."]".mysql_error();
exit;
}
$sql="
CREATE TABLE `test`.`test_table` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) DEFAULT NULL,
`status` char(3) NOT NULL DEFAULT '',
PRIMARY KEY (`id`) USING BTREE,
KEY `Index_2` (`status`)
)";
if(!mysql_query($sql)){
echo "sql=[".$sql."]".mysql_error();
exit;
}
/* データ登録 */
for ($i=0;$i<10000;$i++){
$sql="insert into test_table(name,status)values('test tarao ".$i."','0')";
if(!mysql_query($sql)){
echo "sql=[".$sql."]".mysql_error();
exit;
}
}
/* データ更新 */
for ($i=0;$i<10;$i++){
$id=rand(1,1000); //1~1000までの乱数
$sql="update test_table set status='1' where id='".$id."'";
if(!mysql_query($sql)){
echo "sql=[".$sql."]".mysql_error();
exit;
}
}
/* START時間 */
$time_start = microtime(true);
/* SELECT実行 */
$cnt=10;
for ($i=0;$i
# /usr/bin/php test.php 回数=10 実行時間=0.004秒 平均=0.000秒
自由に修正して使用してください。

