Home >Backend Development >PHP Tutorial >Example of using the database tracker of zf framework_PHP tutorial
Call the tracker method
//Introduce the Loader class (automatic loading class)
require_once("Zend/Loader.php");
//Use the Loader class to introduce a Db class
Zend_Loader::loadClass("Zend_Db" ; .0.1' ,
'username' => 'root' ,
'password' => '111' ,
'dbname' => 'test',
'profiler' = > "true"
);
//Tell the database and database configuration information operated by the Zend_Db class
$Db = Zend_Db::factory('PDO_Mysql', $Config);
// Execute the encoding statement
$Db -> query("set names utf8");
//------------------------ ----------------------------
$Sql = "select * from gongsi";
$Db -> query ($Sql);
//Call the tracker method
$Profiler = $Db -> getProfiler();
//Get the number of submitted statements
echo "The number of submissions :" . $Profiler -> getTotalNumQueries() . "
";
//Get SQL statement execution information
$Result = $Profiler -> getQueryProfiles();
foreach ( $Result as $key => $value)
{
//Output the executed statement
echo "The text content is: " . $value->getQuery() . "
";
//Output the time it takes to run the statement
echo "The time spent is:" . $value->getElapsedSecs() . "
";
}
// Output the total time spent on all statements
echo "The total time spent is:" . $Profiler -> getTotalElapsedSecs();
?>
www.bkjia.com