日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

PHP ORM框架ezpdo(2)之EZPDOSQL

發(fā)布時(shí)間:2025/7/14 php 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP ORM框架ezpdo(2)之EZPDOSQL 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

其實(shí)這個(gè)框架的所謂ezpdosql就是hibernate的HSQL咯,沒啥的,所以照羅列一次,沒啥特別的

首先是from子句
$m = epManager::instance();
?

$books = $m->find("from Book as b where b.title = ?", $title);
?
//like的例子
$books = $m->find("from Book as b where b.title like 'Intro%'");
?
// null的例子
$books = $m->find("from Book as b where b.title is null");
?

$books = $m->find("from Book as b where b.pages < ?", $pages);
?
$books = $m->find("from Book as b where b.title like ? and b.pages < ?", $title, $pages);

之后是支持in參數(shù)了

$books = $m->find("from Book as b where b.price in (2.50, 100.01)");

$books = $m->find("from Book as b where b.author.name in ('Joe Smith', 'Jane Smith')");

in里面也支持?jǐn)?shù)組
books = $m->find("from Book as b where b.price in (?)", array(2.50, 100.01));

$books = $m->find("from Book as b where b.author.name in (?)", array('Joe Smith', 'Jane Smith'));


當(dāng)然要支持sort和limit了
// find books and sort by book id (default ascending order)
$books = $m->find("from Book as b where b.title like ? order by b.id", $title);
?
// find books and sort by id in ascending order
$books = $m->find("from Book as b where b.title like ? order by b.id asc", $title);
?
// find books and sort by id in desscending order
$books = $m->find("from Book as b where b.title like ? order by b.id desc", $title);
?
// find books and sort by id in desscending order and limit to the first two only
$books = $m->find("from Book as b where b.title like ? order by b.id desc limit 0, 2", $title);

支持以下的聚合函數(shù)
AVG(),
COUNT(),
MAX(),
MIN()
S
UM()
例子
$cost = $m->find("sum(price) from Book where title like '%PHP%'");
$num_pages = $m->find("sum(pages) from Book where title like '%PHP%'");
$num_books = $m->find("count(*) from Book where title like '%PHP%'");
$cost_per_page = $cost/$num_pages;
$cost_per_book = $cost/$num_books;

更復(fù)雜一點(diǎn)的例子,這里涉及到關(guān)聯(lián)對(duì)象的HQL

$authors = $m->find("from Author as a where a.contact.zipcode = '12345');

這里,假設(shè)Author類和Contact類有一對(duì)一的關(guān)系,zipcode是contact類的一個(gè)屬性,這里是找出所有作者的聯(lián)系方式中郵政編碼為12345的記錄了。

在已經(jīng)有雙向關(guān)聯(lián)的對(duì)象中,如何用ezpdoz的SQL呢,舉例子如下
假如要找所有smith作者寫的書,則
$books = $m->find("from Book as b where b.authors.contains(a) and a.name = 'Smith'");
因?yàn)閍uthors和books是多對(duì)多關(guān)系,這里要用contains函數(shù)
.

總結(jié)

以上是生活随笔為你收集整理的PHP ORM框架ezpdo(2)之EZPDOSQL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。