NotORM (php orm framework) example code _ PHP Tutorial

Source: Internet
Author: User
NotORM (php orm framework) sample code. In the download topic, we released NotORM, a completely free PHP library to simplify interaction with databases. The most distinctive feature is that it is very easy to process table associations. In the download topic, we released NotORM, a completely free PHP library 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.

Below are some examples of NotORM code:

Connect to the database:

Copy to ClipboardReference: [www.bkjia.com] include "NotORM. php ";
$ Pdo = new PDO ("mysql: dbname = software ");
$ Db = new NotORM ($ pdo );

Read data:

Copy to ClipboardReference: [www.bkjia.com] foreach ($ db-> application () as $ application) {// get all applications
Echo "$ application [title] \ n"; // print application title
}

Conditional query:

Copy to ClipboardReference: [www.bkjia.com] $ applications = $ db-> application ()
-> Select ("id, title ")
-> Where ("web LIKE? "," Http: // % ")
-> Order ("title ")
-> Limit (10)
;
Foreach ($ applications as $ id => $ application ){
Echo "$ application [title] \ n ";
}

Read results:

Copy to ClipboardReference: [www.bkjia.com] $ application = $ db-> application [1]; // get by primary key
$ Application = $ db-> application ("title =? "," Adminer ")-> fetch ();

Process Table Association:

Copy to ClipboardReference: [www.bkjia.com] echo $ application-> author ["name"]. "\ n"; // get name of the application author
Foreach ($ application-> application_tag () as $ application_tag) {// get all tags of $ application
Echo $ application_tag-> tag ["name"]. "\ n"; // print the tag name
}

JOIN query:

Copy to ClipboardReference: [www.bkjia.com] // get all applications ordered by author's name
Foreach ($ db-> application ()-> order ("author. name") as $ application ){
Echo $ application-> author ["name"]. ": $ application [title] \ n ";
}

Result set group:

Copy to ClipboardReference: [www.bkjia.com] echo $ db-> application ()-> max ("id"); // get maximum ID
Foreach ($ db-> application () as $ application ){
// Get count of each application's tags
Echo $ application-> application_tag ()-> count ("*"). "\ n ";
}

Complete instance:

Copy to ClipboardReference: [www.bkjia.com] Include "NotORM. php ";
$ Connection = new PDO ("mysql: dbname = software ");
$ Software = new NotORM ($ connection );

Foreach ($ software-> application ()-> order ("title") as $ application) {// get all applications ordered by title
Echo "$ application [title] \ n"; // print application title
Echo $ application-> author ["name"]. "\ n"; // print name of the application author
Foreach ($ application-> application_tag () as $ application_tag) {// get all tags of $ application
Echo $ application_tag-> tag ["name"]. "\ n"; // print the tag name
}
}
?>

The PHP library is used to simplify interaction with databases. The most distinctive feature is that it is very simple to process table associations ....

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.