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