Just to clarify here...
Javascript doesn't connect to the database. Javascript (AJAX) connects to a page that renders the data via PHP code that connects to the database. AJAX then displays the results of the page.
You probably don't need AJAX for this though. You can easily get the time elapsed on the page load (you have to load the page at least once) and have javascript simply count up from there.