PhpNotORM (php orm framework) Sample code

Source: Internet
Author: User
PhpNotORM (php orm framework) Sample code

NotORM is a PHP library used to simplify interaction with databases. The most distinctive feature is that it is very easy to process table associations. In addition, NotORM has a very high performance and is set to a higher than the built-in driver.

Connect to database

  1. Include "NotORM. php ";
  2. $ Pdo = new PDO ("mysql: dbname = software ");
  3. $ Db = new NotORM ($ pdo );

Read Data

  1. Foreach ($ db-> application () as $ application) {// get all applications
  2. Echo "$ application [title] \ n"; // print application title
  3. }

Conditional query

  1. $ Applications = $ db-> application ()
  2. -> Select ("id, title ")
  3. -> Where ("web LIKE? "," Http: // % ")
  4. -> Order ("title ")
  5. -> Limit (10)
  6. ;
  7. Foreach ($ applications as $ id => $ application ){
  8. Echo "$ application [title] \ n ";
  9. }

Read results

  1. $ Application = $ db-> application [1]; // get by primary key
  2. $ Application = $ db-> application ("title =? "," Adminer ")-> fetch ();

Process Table Association

  1. Echo $ application-> author ["name"]. "\ n"; // get name of the application author
  2. Foreach ($ application-> application_tag () as $ application_tag) {// get all tags of $ application
  3. Echo $ application_tag-> tag ["name"]. "\ n"; // print the tag name
  4. }

JOIN query

  1. // Get all applications ordered by author's name
  2. Foreach ($ db-> application ()-> order ("author. name") as $ application ){
  3. Echo $ application-> author ["name"]. ": $ application [title] \ n ";
  4. }

Result set group

  1. Echo $ db-> application ()-> max ("id"); // get maximum ID
  2. Foreach ($ db-> application () as $ application ){
  3. // Get count of each application's tags
  4. Echo $ application-> application_tag ()-> count ("*"). "\ n ";
  5. }

Complete example

  1. Include "NotORM. php ";
  2. $ Connection = new PDO ("mysql: dbname = software ");
  3. $ Software = new NotORM ($ connection );
  4. Foreach ($ software-> application ()-> order ("title") as $ application) {// get all applications ordered by title
  5. Echo "$ application [title] \ n"; // print application title
  6. Echo $ application-> author ["name"]. "\ n"; // print name of the application author
  7. Foreach ($ application-> application_tag () as $ application_tag) {// get all tags of $ application
  8. Echo $ application_tag-> tag ["name"]. "\ n"; // print the tag name
  9. }
  10. }
  11. ?>

NotORM, php, ORM

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.