Home > php教程 > php手册 > ZF框架Db类状态器简单用法

ZF框架Db类状态器简单用法

WBOY
Release: 2016-06-06 19:33:14
Original
1183 people have browsed it

作业练习 Zend Framework ?php/*状态器的使用方法*///引入Loader类(自动加载类)require_once("Zend/Loader.php");//使用Loader类引入一个Db类Zend_Loader::loadClass("Zend_Db");//引入Zend_Db的状态器Zend_Loader::loadClass("Zend_Db_Statement_Pdo");//配

作业练习 Zend Framework
<?php
/*状态器的使用方法*/

//引入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'
				);
//告诉Zend_Db类所操作的数据库和数据库配置信息
$Db = Zend_Db::factory('PDO_Mysql' , $Config); 
//执行编码语句 
$Db -> query("set names utf8");
//临时这是一个表名变量
$table = 'sanguo';
//SQL语句,条件使用?号来代代替
$Sql = "select * from sanguo";
//实例化Zend_Db的状态器
$State = new Zend_Db_Statement_Pdo($Db , $Sql);
//执行SQL语句
$State -> execute();
//将执行的SQL结果集返回(需要循环)
$Result = $State -> fetchAll();
?>
Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template