国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

[轉(zhuǎn)]ZendFramework數(shù)據(jù)庫(kù)操作總結(jié)

2019-11-15 01:27:45
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
View Post[轉(zhuǎn)]ZendFramework數(shù)據(jù)庫(kù)操作總結(jié)

Zend_Db數(shù)據(jù)庫(kù)知識(shí)

例子:

Model文件:

$this->fetchAll("is_jian=1","id DESC",0,2)->toArray();//根據(jù)is_jian=1,按id倒序排列取前2條記錄當(dāng)?shù)谝粋€(gè)參數(shù)為null時(shí),則直接按id倒序排列ASC為正序。

路由文件:

$video=new Video();//實(shí)例化數(shù)據(jù)庫(kù)類(lèi)

$this->view->get2Video =$video->get2Video();//取到2條首頁(yè)推薦的數(shù)據(jù)

index.phtml文件:

<?php foreach ($this->get2Video as $video): ?>

<?=$video['id']; ?>

<?=$video['name']; ?>

<? endforeach; ?>

添加引號(hào)防止數(shù)據(jù)庫(kù)攻擊

quote用法

$value = $db->quote('St John"s Wort');

// $value 現(xiàn)在變成了 '"St John/"s Wort"' (注意兩邊的引號(hào))

// 為數(shù)組加引號(hào)

$value = $db->quote(array('a', 'b', 'c'));

// $value 現(xiàn)在變成了 '"a", "b", "c"' (","分隔的字符串)

quoteInto用法

echo $where = $db->quoteInto('id = ?', 1);

// $where 現(xiàn)在為 'id = "1"' (注意兩邊的引號(hào))

// 在where語(yǔ)句中為數(shù)組加上引號(hào)

$where = $db->quoteInto('id IN(?)', array(1, 2, 3));

// $where 現(xiàn)在為 'id IN("1", "2", "3")' (一個(gè)逗號(hào)分隔的字符串)

(1)數(shù)據(jù)查詢(xún)總結(jié)

直接進(jìn)行查詢(xún).( 使用完整的sql語(yǔ)句)

//function quoteInto($text, $value, $type = null, $count = null)

$db = $this->getAdapter();

$sql = $db->quoteInto('SELECT * FROM `m_video` WHERE `is_guo` =?', '1');

$result = $db->query($sql);

// 使用PDOStatement對(duì)象$result將所有結(jié)果數(shù)據(jù)放到一個(gè)數(shù)組中

$videoArray = $result->fetchAll();

fetchAll用法

fetchAll($where = null, $order = null, $count = null, $offset = null)

取回結(jié)果集中所有字段的值,作為連續(xù)數(shù)組返回,如果參數(shù)不設(shè)置就寫(xiě)成null

可以取回結(jié)果集的指定條數(shù)

$videoArray=$this->fetchAll("is_jian=1 and is_guo=1","id DESC",0,2)->toArray();

fetchAssoc用法

fetchAssoc($sql, $bind = array())

取回結(jié)果集中所有字段的值,作為關(guān)聯(lián)數(shù)組返回, 第一個(gè)字段作為碼

$db = $this->getAdapter();

$videoArray=$db->fetchAssoc("SELECT * FROM m_video WHERE `is_jian` = :title",array('title' => '1'));

fetchCol用法

fetchCol($sql, $bind = array())

取回所有結(jié)果行的第一個(gè)字段名

$db = $this->getAdapter();

$videoArray=$db->fetchCol("SELECT name FROM m_video WHERE `is_jian` = :title",array('title' => '1'));

fetchOne用法

fetchOne($sql, $bind = array())

只取回第一個(gè)字段值

$db = $this->getAdapter();

echo $videoArray=$db->fetchOne("SELECT count(*) FROM m_video WHERE `is_jian` = :title",array('title' => '1'));

fetchPairs用法

fetchPairs($sql, $bind = array())

取回一個(gè)相關(guān)數(shù)組,第一個(gè)字段值為碼(id),第二個(gè)字段為值(name)

返回:Array( [1] => 十二生肖奇緣[2] => 桃花運(yùn)),1,2:為id字段。

$db = $this->getAdapter();

$videoArray=$db->fetchPairs("SELECT id, name FROM m_video WHERE is_jian = :title",array('title' => '1'));

fetchRow用法

fetchRow($where = null, $order = null)

只取回結(jié)果集的第一行

$videoArray=$this->fetchRow("is_jian=1 and is_guo=1", 'id DESC')->toArray();

query用法

//function query($sq

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青州市| 永城市| 巴中市| 二连浩特市| 万山特区| 阿坝县| 睢宁县| 合山市| 新源县| 怀仁县| 海晏县| 华亭县| 大关县| 微山县| 安国市| 裕民县| 永丰县| 报价| 禄丰县| 浦江县| 错那县| 龙泉市| 海宁市| 衡山县| 吐鲁番市| 陇西县| 紫金县| 西宁市| 三门县| 贺州市| 西峡县| 北海市| 临澧县| 长兴县| 鄂州市| 高阳县| 庆阳市| 商丘市| 红桥区| 怀安县| 会宁县|