Log Database with executime

จาก Wiki2

ข้ามไปที่: นำทาง, สืบค้น
<?php
   $mtime = microtime();
   echo $mtime."<br/>";
   
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;
   echo $starttime."<br/>";
   usleep(100);
   $mtime = microtime();
      echo $mtime."<br/>";
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   echo $endtime."<br/>";
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";  
     $DBhost = "localhost";
     $DBuser = "root";
     $DBpass = "*****";
     $DBname = "wd";
     $table = "log";
     mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
     mysql_select_db("$DBname") or die("Unable to select databaser name = $DBname");
     $difftime = ($endtime - $starttime);
     $logtext = "Thisis the test";
     $sqlquery = "INSERT INTO $table (starttime,endtime,difftime,log) VALUES ($starttime,$endtime,$difftime,'$logtext')";  // Please not the $logtext had to be suround with ''
     $results = mysql_query($sqlquery);
     mysql_close();

   
   
   
?> 
เครื่องมือส่วนตัว