<?php
// 建立一个 adapter
require_once 'Zend/Db.php';
$params = array (
'host' => '127.0.0.1',
'username' => 'malory',
'password' => '******',
'dbname' => 'camelot'
);
$db = Zend_Db::factory('PDO_MYSQL', $params);
// 为所有的Zend_Db_Table对象设定默认的adapter
require_once 'Zend/Db/Table.php';
Zend_Db_Table::setDefaultAdapter($db);
?>
<?php
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
?>
<?php
class ClassName extends Zend_Db_Table
{
// 默认表名为 'class_name'
// 但是我们也可以对应其它表
protected $_name = 'another_table_name';
}
?>
<?php
class ClassName extends Zend_Db_Table
{
// 默认主键为'id'
// 但我们也可以设定其他列名为主键
protected $_primary = 'another_column_name';
}
?>
<?php
class ClassName extends Zend_Db_Table
{
protected function _setup()
{
$this->_name = 'another_table_name';
$this->_primary = 'another_column_name';
parent::_setup();
}
}
?>
<?php
//
// INSERT INTO round_table
// (noble_title, first_name, favorite_color)
// VALUES ("King", "Arthur", "blue")
//
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
$data = array(
'noble_title' => 'King',
'first_name' => 'Arthur',
'favorite_color' => 'blue',
)
$id = $table->insert($data);
?>
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
$db = $table->getAdapter();
$set = array(
'favorite_color' => 'yellow',
)
$where = $db->quoteInto('first_name = ?', 'Robin');
$rows_affected = $table->update($set, $where);
<?php
//
// DELETE FROM round_table
// WHERE first_name = "Patsy"
//
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
$db = $table->getAdapter();
$where = $db->quoteInto('first_name = ?', 'Patsy');
$rows_affected = $table->delete($where);
?>
<?php
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
// SELECT * FROM round_table WHERE id = "1"
$row = $table->find(1);
// SELECT * FROM round_table WHERE id IN("1", "2", 3")
$rowset = $table->find(array(1, 2, 3));
?>
<?php
//
// SELECT * FROM round_table
// WHERE noble_title = "Sir"
// AND first_name = "Robin"
// ORDER BY favorite_color
//
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
$db = $table->getAdapter();
$where = $db->quoteInto('noble_title = ?', 'Sir')
. $db->quoteInto('AND first_name = ?', 'Robin');
$order = 'favorite_color';
$row = $table->fetchRow($where, $order);
?>
<?php
class RoundTable extends Zend_Db_Table {}
$table = new RoundTable();
$db = $table->getAdapter();
// SELECT * FROM round_table
// WHERE noble_title = "Sir"
// ORDER BY first_name
// LIMIT 10 OFFSET 20
$where = $db->quoteInto('noble_title = ?', 'Sir');
$order = 'first_name';
$count = 10;
$offset = 20;
$rowset = $table->fetchAll($where, $order, $count, $offset);
?>
<?php
class RoundTable extends Zend_Db_Table
{
public function insert($data)
{
// 添加一个时间戳
if (empty($data['created_on'])) {
$data['created_on'] = time();
}
return parent::insert($data);
}
public function update($data)
{
// 添加一个时间戳
if (empty($data['updated_on'])) {
$data['updated_on'] = time();
}
return parent::update($data);
}
}
?>
<?php
class RoundTable extends Zend_Db_Table
{
public function findAllWithName($name)
{
$db = $this->getAdapter();
$where = $db->quoteInto("name = ?", $name);
$order = "first_name";
return $this->fetchAll($where, $order);
}
}
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有