kgizzy — 2014-01-08T03:10:03-05:00 — #1
Hi I would love to display a progress bar when inserting data from one mysql table from another mysql table.
The examples I keep coming across are particularly concerned with progress bars that are displayed when uploading data from a form and displaying it on another form and I just can't seem make the current code I have to display the bar eventhough the query is executed successfully.
Your help in this regard will be highly appreciated.
mittineague — 2014-01-08T05:10:44-05:00 — #2
Hi kgizzy, welcome to the forums,
I suppose it might be possible to do, but why?
Database INSERT queries happen server-side and usually run so fast that for all intents and purposes they're "instant". Even major database manipulalation runs fairly fast.
Any progress bar would likely "blink" and even then passing the info back via an HTTP request would take longer than the INSERT took to run.
IMHO it would be better to send back a simple "success" type of message.
Are you sure you shouldn't be looking into optimizing your tables and queries instead?
kgizzy — 2014-01-08T06:12:34-05:00 — #3
The thing is I should have a progress bar for every operation that occurs on my web based application and the starting point is having a progress bar for a mysql query.
Displaying the progress bar seems to be a mission impossible but everything else works perfectly.
Thanks for taking the time to offer your helping hand its much appreciated.
mittineague — 2014-01-08T15:45:43-05:00 — #4
It's not impossible, just how do you show the progress for something that typically takes a mere fraction of a second, or only a few seconds at most?
Often the "bottle necks" in a site visitors experience have more to do with the transfer of data via HTTP requests. eg. heavy weight img, swf, files.
Though sometimes slowdown or even hang can be a result of poor code.
Maybe what you are looking for is Benchmarking? Maybe this recent thread will give some ideas? http://www.sitepoint.com/forums/showthread.php?1185776-How-to-measure-time-with-microsecond-precision-on-a-32-bit-system
jordan_windebank — 2014-01-08T20:24:23-05:00 — #5
Any progress bar component will need to be given the update percentage from the process being run. What does the SQL statement look like that is performing the insert? If it is inserting a lot of rows perhaps you could break it in to chunks and report the progress after each chunk?
This would most likely slow the overall insert but would give you the progress if the usability factor was worth it.
kgizzy — 2014-01-09T03:56:48-05:00 — #6
@Mittineague my code already has the duration of the whole execution process which works perfectly its just one aspect of my project that doesn't seem to work which is the progress bar. My script when executed should display the progress bar and the total time taken to execute the query. At the moment the query does work and the total time taken is functional.
@Jordan Windebank here's the code snippet:
$time_start = microtime(true);
$mysqlserver = "localhost";
$user = "root";
$pass = "";
$db = "Profusion";
$link = mysql_connect( "$mysqlserver", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
//print "Successfully connected to server<P>";
mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
//print "Successfully selected database \\"$db\\"<P>";
$result3=mysql_query("INSERT INTO dest_table.create_info SELECT * from Profusion.source_cdr") or die(mysql_error());
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Total time taken :"." ".round($time,6) . " s";
There are 28 rows to be inserted in the table so it's not really big.
I am trying to utilize the article written by TIm ad he passes the progress bar to a form unfortunately. link below
mittineague — 2014-01-09T04:59:02-05:00 — #7
Yes, but that article is about uploading (the aforementioned HTTP requests) not database profiling.
Is this something you want only for yourself or for every user?
kgizzy — 2014-01-09T05:04:18-05:00 — #8
I am running a mini application here at work so its currently for myself. I here what you are saying.
Thanks alot I'll try and re-direct my approach. Your efforts are highly appreciated.
spacephoenix — 2014-02-19T15:37:49-05:00 — #9
Please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn't tie you down so much to a particular database server software.
Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.