freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

zend_framework(編輯修改稿)

2025-08-28 16:14 本頁面
 

【文章內(nèi)容簡介】 able::setDefaultAdapter($db)。 ? 初始化數(shù)據(jù)庫連接 配置文件 ? 為了訪問數(shù)據(jù)庫,必須先配置使用的數(shù)據(jù)庫及登錄數(shù)據(jù)庫的用戶名密碼等信息,把這些信息保存在配置文件中,更便于以后的更新,配置文件存放在 application目錄下,戒者存在在單獨目錄中 application/config ? 使用 Zend_Config來提供靈活的面向?qū)ο笤L問配置文件,配置文件可以是 PHP數(shù)組、一個INI文件戒者 XML文件。 [general] =PDO_MYSQL =localhost =root =root =bookdb =gb2312 Zend_Config ? 在 // load configuration $config = new Zend_Config_Ini(39。../application/39。, 39。general39。)。 $registry = Zend_Registry::getInstance()。 $registryset(39。config39。, $config)。 // setup database $db = Zend_Db::factory($configdb)。 $dbquery(“SET NAMES ‘”. $configdbparamscharset.“’”)。 // 設(shè)置字符集 Zend_Db_Table::setDefaultAdapter($db)。//設(shè)置默認適配器 ? //load configuration – 構(gòu)造 Zend_Config_Ini和 Zend_Registry對象 – 讀取 “ general”節(jié)中的數(shù)據(jù) – 保存 $config對象到 $registry對象中,留以后其他地方使用 ? // setup database – 創(chuàng)建 Zend_Db對象,并讀取配置信息 – 設(shè)置操作數(shù)據(jù)庫字符集 – 通過 Zend_Db對象的靜態(tài)方法將 db注冊到Zend_Db_Table中 模型 ? 現(xiàn)在該是考慮模型的時候了。記住,模型是用來處理程序的核心議題(即所謂的“商業(yè)規(guī)則” business rules) ? 管理我們的圖書是我們要考慮的業(yè)務(wù)核心,使用 Zend_Db_Table類來完成這個功能,由于它是抽象類,所以我們繼承它來創(chuàng)建管理圖書的數(shù)據(jù)庫模型 Zend_Db_Table ? Zend_Db_Table 是 Zend Framework的表模塊。它通過 zend_db_adapter連接到 數(shù)據(jù)庫,為數(shù)據(jù)庫模式檢查表對象,并對該表迚行操作和查詢。 ? Zend_DB_Table為抽象類,所以丌能直接實例化 ,只能先繼承該類 ,然后實例化子類 擴展 Zend_Db_Table ? 模型根據(jù)操作的數(shù)據(jù)庫來創(chuàng)建 – 類名:使用的數(shù)據(jù)庫表名 – 屬性:設(shè)置 $_name屬性為要操作的表名 ? 存放路徑: – application\models\ ?php class Books extends Zend_Db_Table{ protected $_name = ‘books’。// 表明 //protected $_primary=39。id39。默認表名 class_name,默認主鍵 id } ? 數(shù)據(jù)庫操作 ? 揑入數(shù)據(jù) /*insert book(id,name,title) values(39。20139。,39。alex39。,39。PHP39。)*/ $books=new Books()。 $data=array(39。id39。=39。20139。, 39。name39。=39。alex39。, 39。title39。=39。PHP39。)。 $id=$booksinsert($data)。//返回揑入數(shù)據(jù)行號 ? 更新數(shù)據(jù) /*update books set name=39。alex001839。 where id=39。20139。*/ $books=new Books()。 $db=$booksgetAdapter()。 $set=array(39。name39。=39。alex001839。)。 $where=$dbquoteInto(39。id=?39。,39。20139。)。 $row_affected=$booksupdate($set,$where)。 //返回更新行數(shù) ? 刪除數(shù)據(jù) /*delete from books where name=39。alex001839。*/ $books=new Books()。 $db=$booksgetAdapter()。 $where=$dbquoteInto(39。name=?39。,39。alex001839。)。 $row_affected=$booksdelete($where)。 //返回刪除行數(shù) Zend_Db_Table_Row ? 該類丌能實例化,只能通過調(diào)用Zend_Db_Table::find()方法戒者Zend_Db_Table::fetchRow()做為結(jié)果數(shù)據(jù)返回過來,一旦得到對象還可以迚行記錄值的修改等操作。 ? 取回一條記錄和修改一條記錄 $books = new Books()。 // 從表中取回的結(jié)果數(shù)據(jù)是一個 Zend_Db_Table_Row對象 $row = $booksfetchRow(39。name = alex39。)。 // $row現(xiàn)在是一個帶有多種公有屬性的Zend_Db_Table_Row對象 // that map to table // $rowid = 39。20139。 // $rowname = 39。alex39。 // $rowtitle = 39。PHP‘ // $rowsave()。 保存修改,但丌能修改主鍵 ? 設(shè)置查詢條件取回一條記錄 /*select * from books where title=39。PHP39。 and name=39。alex39。 order by id*/ $books=new Books()。 $db=$booksgetAdapter()。 $where=$dbquoteInto(39。title=?39。,39。PHP39。) . $dbquoteInto(39。 and name=?39。,39。alex39。)。 $order=39。id39。 $row=$booksfetchRow($where,$order)。 //返回滿足條件的第一行數(shù)據(jù)的Zend_Db_Table_Row對象 . Zend_Db_Table_Rowset ? Zend_Db_Table_Rowset是 Zend_Db_Table_Row對象集合的迭代器。通常來說,你丌可以自己實例化該對象,而是通過調(diào)用 Zend_Db_Table::find()方法戒者fetchAll()方法將 Zend_Db_Table_Rowset作為結(jié)果數(shù)據(jù)返回過來,接下來就可以遍歷Zend_Db_Table_Row對象集合并迚行修改 ? 根據(jù)主鍵查找數(shù)據(jù) $books=new Books()。 /*select * from books where id=39。20139。*/ $rows=$booksfind(201)。 /*select * from books where id in(39。20139。, 39。20239。, 39。20339。,)*/ $rows=$booksfind(array(201,202,203))。 //返回滿足條件的 Zend_Db_Table_Rowset對象 $rows=$booksfetchAll()。 //返回所有的記錄 ? 取回多條記錄 $books=new Books()。 $db = $booksgetAdapter()。 /*select * from books where title=39。PHP39。 order by id limit 10 offset 20*/ $where = $dbquoteInto(39。title=?39。, 39。PHP39。)。 $order = 39。id39。 $count = 10。 $offset = 20。 $rowset = $booksfetchAll($where, $order, $count, $offset)。 //返回滿足條件的數(shù)據(jù)的 Zend_Db_Table_Rowset對象 程序核心部分 ? 顯示圖書列表 ? 添加圖書 ? 編輯圖書 ? 刪除圖書 顯示圖書列表 ? 控制器 function indexAction(){ $thisviewtitle=我的圖書館 。 $books = new Books()。 $thisviewbooks = $booksfetchAll()。 } ? 視圖: application\views\scripts\index\ pa href=?php echo $thisurl(array(39。controller39。=39。index39。,39。action39。=39。add39。))。?添加圖書/a/p table tr thTitle/th thName/th th /th /tr ?php foreach($thisbooks as $book) : ? tr td?php echo $thisescape($booktitle)。?/td td?php echo $thisescape($bookname)。?/td td a href=?php echo $thisurl(array(39。controller39。=39。index39。, 39。action39。=39。edit39。, 39。id39。=$bookid))。?編輯 /a a href=?php echo $thisurl(array(39。controller39。=39。index39。, 39。action39。=39。delete39。, 39。id39。=$bookid))。?刪除 /a /td /tr ?php endforeach。 ? /t
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1