php - How to get the number of times a query execute -
in php, there way total number of times query executed in 24 hours?
try having table. lets name executetb
column:
exid
(int
, primary , auto-increment)executionnumber
(int
)datetimeexec
column (which should havedatetime
data type)
if page access, system should run query check if there existing data in executetb
today. , standby current number of execution before run main query:
$today = date("y-m-d"); if($stmt = $connection->prepare("select exid, executionnumber executetb date(datetimeexec) = ? ")){ $stmt->bind_param("s",$today); $stmt->execute(); $stmt->store_result(); $check = $stmt->num_rows; if($check == 0){ /* if no existing data today */ $exact = date("y-m-d h:i:s"); /* current date , time */ $executionnumber = 0; /* start 0 */ if($stmt2 = $connection->prepare("insert executetb (executionnumber, datetimeexec) values (?)")){ $stmt2->bind_param("is",$executionnumber,$exact); $stmt2->execute(); $exid = $stmt2->insert_id; /* inserted id */ $stmt2->close(); } /* end of creating data today */ } /* end of if no existing date today */ else { /* else, if there data today */ $stmt->bind_result($exid,$executionnumber); /* current execution number today */ $stmt->fetch(); } $stmt->close(); } /* end of prepared statement */
and use if()
statement when execute query:
if($stmt = $connection->prepare("select column table")){ /* when statement true */ $stmt->execute(); $executionnumber = $executionnumber + 1; /* increment current number of execution */ mysqli_query($connection,"update executetb set executionnumber = $executionnumber exid = '$exid'"); /* update execution table */ $stmt->close(); }
function:
to put in function, create function:
function execute($today){ /* put here first code i've provided except date today */ return $executionnumber; }
and call function:
if(/* main statement query here */){ $today = date("y-m-d"); $numberofexec = execute($today); $numberofexec = $numberofexec + 1; mysqli_query($con,"update executetb set executionnumber = '$numberofexec' date(datetimeexec) = '$today'"); } /* end of main statement */
Comments
Post a Comment