程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> NotORM(PHP的ORM框架)示例代碼

NotORM(PHP的ORM框架)示例代碼

編輯:關於PHP編程

在烈火下載欄目,我們發布了NotORM,這是一個完全免費的 PHP 庫,用來簡化和數據庫的交互。最有特色的功能是處理表關聯關系非常簡單。另外 NotORM 的性能非常的高,設置高過內置的驅動。

下邊來看一些NotORM的示例代碼:

連接數據庫:

Copy to ClipboardLiehuo.Net Codes引用的內容:[www.bkjia.com] include "NotORM.php";
$pdo = new PDO("mysql:dbname=software");
$db = new NotORM($pdo);

讀取數據:

Copy to ClipboardLiehuo.Net Codes引用的內容:[www.bkjia.com] foreach ($db->application() as $application) { // get all applications
echo "$application[title]\n"; // print application title
}

條件查詢:

Copy to ClipboardLiehuo.Net Codes引用的內容:[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";
}

讀取結果:

Copy to ClipboardLiehuo.Net Codes引用的內容:[www.bkjia.com] $application = $db->application[1]; // get by primary key
$application = $db->application("title = ?", "Adminer")->fetch();

處理表關聯:

Copy to ClipboardLiehuo.Net Codes引用的內容:[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聯合查詢:

Copy to ClipboardLiehuo.Net Codes引用的內容:[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";
}

結果集分組:

Copy to ClipboardLiehuo.Net Codes引用的內容:[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";
}

完整實例:

Copy to ClipboardLiehuo.Net Codes引用的內容:[www.bkjia.com] <?php
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
}
}
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved