Zend Framework

出自ProgWiki

跳轉到: 導航, 搜尋

Zend Framework,參照:『維基百科~Zend_Framework

官方討論區

目錄

技術文件

MySQL存取

開啟MySQL資料庫

//指向放ZendFramework的上一層目錄
set_include_path(dirname(__FILE__) . '/libraries/');
 
//MySQL的存取連線定義
$DB_CONFIG_Params = array('host'     => '127.0.0.1',
                 	'username' => 'root',
                 	'password' => 'pw',
                 	'dbname'   => 'mydb');
 
 
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload(); 
 
$db = Zend_Db::factory('Pdo_Mysql', $DB_CONFIG_Params);
 
Zend_Db_Table::setDefaultAdapter($db);

查詢資料

$select = $db->select();
 
$select->from('mytable', '*')
	->where('insertdate = ?', '2006/01/01')
	->order('insertdate')
	->limit(10,20);
 
$sql = $select->__toString();
 
$rows = $db->fetchAll($sql);

查詢資料筆數

$select = $db->select();
 
$select->from('mytable', 'count(*)')
	->where('insertdate = ?', '2006/01/01');
 
$sql = $select->__toString();
 
$counts = $db->fetchOne($sql);

新增資料

$row = array (
    'noble_title'    => 'King',
    'first_name'     => 'Arthur',
    'favorite_color' => 'blue',
    'insertdate'     => '2006/01/01'
);
 
// 插入資料的Table名稱
$table = 'mytable';
 
// 插入資料, 並傳回影響的資料筆數
$rows_affected = $db->insert($table, $row);

更新資料

$set = array (
    'favorite_color' => 'yellow',
);
 
// 更新的数据表
$table = 'mytable';
 
// where 條件式
$where = $db->quoteInto('first_name = ?', 'Robin');
 
// 更新資料, 並傳回影響的資料筆數
$rows_affected = $db->update($table, $set, $where);

删除資料

$table = 'mytable';
 
// where 條件式
$where = $db->quoteInto('first_name = ?', 'Patsy');
 
// 删除資料, 並傳回影響的資料筆數
$rows_affected = $db->delete($table, $where);
個人工具
名字空間
變換
動作
導航
分類
其他
技術類News或部落格
工具箱