zf框架的db类select查询器join链表使用示例(zend框架


<?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',
    'profiler' => "true"
    );
//告诉Zend_Db类所操作的数据库和数据库配置信息
$Db = Zend_Db::factory('PDO_Mysql' , $Config);
//执行编码语句
$Db -> query("set names utf8");
//-----------------------------------------------
$Select = $Db ->select();
$Select -> from('sanguo','*');
$Select -> join('dengji','sanguo.s_dengji = dengji.d_id');
$Select -> order('s_dengji asc');
$Reslut = $Db -> fetchAll($Select);
echo "<table>";
foreach ($Reslut as $key => $value)
{
 echo "<tr>";
 foreach ($value as $key2 => $value2)
 {
  echo "<td>" . $value2 . "</td>";
 }
 echo "</tr>";
}
echo "</table>";
?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ee14832582f6706a37f10063b8dec7fe.html