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
- Include "NotORM. php ";
- $ Pdo = new PDO ("mysql: dbname = software ");
- $ Db = new NotORM ($ pdo );
Read Data
- Foreach ($ db-> application () as $ application) {// get all applications
- Echo "$ application [title] \ n"; // print application title
- }
Conditional query
- $ 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
- $ Application = $ db-> application [1]; // get by primary key
- $ Application = $ db-> application ("title =? "," Adminer ")-> fetch ();
Process Table Association
- 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
- // 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
- 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 example
- 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
- }
- }
- ?>
|
NotORM, php, ORM