Home > Backend Development > PHP Tutorial > zf框架的数据库追踪器使用示例_php实例

zf框架的数据库追踪器使用示例_php实例

WBOY
Release: 2016-06-07 17:21:25
Original
751 people have browsed it

调用追踪器的方法

复制代码 代码如下:

$Profiler = $Db -> getProfiler();

复制代码 代码如下:

/*
追踪器的使用方法
*/

//引入Loader类(自动加载类)
require_once("Zend/Loader.php");
//使用Loader类引入一个Db类
Zend_Loader::loadClass("Zend_Db");
//引入Zend_Db的状态器
Zend_Loader::loadClass("Zend_Db_Statement_Pdo");
//配置数据库连接信息
$Config = array('host' => '127.0.0.1' ,
    'username' => 'root' ,
    'password' => '111' ,
    'dbname' => 'test',
    'profiler' => "true"
    );
//告诉Zend_Db类所操作的数据库和数据库配置信息
$Db = Zend_Db::factory('PDO_Mysql' , $Config);
//执行编码语句
$Db -> query("set names utf8");
//-----------------------------------------------------
$Sql = "select * from gongsi";
$Db -> query($Sql);
//调用追踪器的方法
$Profiler = $Db -> getProfiler();
//获取提交语句的条数
echo "提交的个数:" . $Profiler -> getTotalNumQueries() . "
";
//获取SQL语句执行的信息
$Result = $Profiler -> getQueryProfiles();
foreach ($Result as $key => $value)
{
 //输出运行过的语句
 echo "文本内容为:" . $value->getQuery() . "
";
 //输出运行语句所花费的时间
 echo "花费时间为:" . $value->getElapsedSecs() . "
";
}
//输出所有语句花费的总时间
echo "花费的总时间为:" . $Profiler -> getTotalElapsedSecs();
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template