I am a university student and require some help, I have been trying to find out how to show the execution time of simple SQL queries such as insert select delete etc
I have already understood how to insert data into MongoDB but what I need to find now is how to code it so once the code has inserted the data in the DB it shows the time it had taken to perform the insert , the preferred way of showing this would be on a php window once the insert button has been clicked,
All you need to do is assign the return from that function to a variable immediately before you execute the query, and then do it again immediately after the query has executed. Difference between the two is the number of microseconds to execute.
I’m sure there are probably plenty of other ways to do it.
Ok I’ve managed to figure that out … also do you know how we would be able to search data from a php text box into both MySQL and mongodb if they have the same data in them.
The output would be something like this
In the text box I would search ‘London’ and then I would wait for both the Databases to select all attributes with London in them and display how long it had taken to retrieve the data and show it on the page like;
I’d imagine you would just have a separate set of code to access the MySQL database and run the query, which itself is pretty straightforward. Get the text from the form as you did in the code above, sanitise it, build the query and run it on each database. Plenty of sample code if you scroll down a page or two showing how to run a query in MySQL if you’re not familiar with it. Use PDO to run the query on MySQL, or mysqli, but not mysql() calls.
<?php
//------------------------------MONGODB CODE -----------------------------
```
// Connecting to server
$m = new MongoDB\Client("mongodb://localhost:27017");
$db=$m->CSV;
$mObj=$db->Schools;
```
```
if($mObj->find())
{
echo " ";
echo "The search time for all school data is ";
echo " ";
}
else{
echo "some issue";
}
```