Ezpdosql in php orm framework ezpdo (2)

Source: Internet
Author: User

In fact, the so-called ezpdosql of this framework is the hsql of hibernate, nothing, so the list once, nothing special

First, the from clause
$ M = epmanager: instance ();
 

$ Books = $ M-> Find ("from book as B where B. Title =? ", $ Title );
 
// Example of like
$ Books = $ M-> Find ("from book as B where B. Title like 'intro % '");
 
// Null example
$ 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 );

The in parameter is now supported.

$ 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 also supports Arrays
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 '));

Of course, sort and limit are supported.
// 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 );

The following Aggregate functions are supported:
AVG (),
Count (),
Max (),
Min ()
Sum ()
Example
$ 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;

For a more complex example, the hql of the correlated object is involved.

$ Authors = $ M-> Find ("from author as a where a.contact.zip code = '20140901 ');

Here, we assume that the author class has a one-to-one relationship with the contact class. zipcode is an attribute of the contact class. Here we find the zip code 12345 record in all the author's contact information.

How to Use ezpdoz SQL in objects that already have two-way association? An example is as follows:
If you want to find all the books written by Smith
$ Books = $ M-> Find ("from book as B where B. Authors. contains (a) and A. Name = 'Smith '");
Because authors and books have many-to-many relationships, the contains function is used here.
.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.