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.
.