search
Homephp教程php手册zf框架的数据库追踪器使用示例

调用追踪器的方法

复制代码 代码如下:


$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();
?>

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft