3.2 Zend_db_select

Source: Internet
Author: User
Tags sqlite

10.4. Zend_db_select

You can use this object and its corresponding method to build a SELECT query statement, and then generate a string character to be passed to Zend_db_adapter for query or read results.

You can also use a bound argument in your query statement without having to add a reference to the parameter.

10.4.2. Querying multiple columns of data in the same table

10.4.3. Multi-Table union query

10.4.4. Where Condition

10.4.5. GROUP BY clause

10.4.6. Having conditions

10.4.7. ORDER BY clause

10.4.8. Limit restrictions by total and offset
Zend_db_select can support the limit statement limits of the database tier. For some databases, such as MySQL and PostgreSQL. Implementing these is relatively easy, as these databases natively support the "limit:count" syntax.

For some other databases. Microsoft's SQL Server and Oracle, for example, are less simple to implement the limit function because they do not support the limit statement at all.

Ms-sql has a top statement to implement, and for Oracle to implement the limit function, the query statement is more specific.

Due to the way Zend_db_select works internally. We are able to rewrite the SELECT statement to implement the limit functionality of the above open source database system in Oracle.

To limit the returned results by setting the total number and offset of the query, you can use the limit () method, the total value, and an optional offset as the number of parameters to invoke the method.

<?Php///First, a simple "limit:count"$select = $db -Select();$select -From' foo ',' * ');$select -Order(' id ');$select -LimitTen);////In Mysql/psotgresql/sqlite, this statement can be obtained:////SELECT * from Foo//ORDER by ID ASC//LIMIT////But under Microsoft SQL, you can get this statement:////SELECT TOP ten * from FOO//ORDER by ID ASC//////Today is a more complex "limit:count offset:offset" approach$select = $db -Select();$select -From' foo ',' * ');$select -Order(' id ');$select -LimitTen, -);////In Mysql/psotgresql/sqlite, this statement can be obtained:////SELECT * from Foo//ORDER by ID ASC//LIMIT OFFSET////However, under Microsoft SQL, this SQL statement can be obtained because the offset feature is not supported:////SELECT * FROM (//SELECT TOP ten * FROM (//SELECT TOP * from foo ORDER by ID DESC//     ) ORDER by ID ASC// )////Zend_db_adapter be able to complete the dynamic creation of SQL statements on its own initiative.//?

>

10.4.9. Limit restrictions by number of pages and totals

3.2 Zend_db_select

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.