NotORM 是一個 PHP 函式庫,用來簡化和資料庫的互動。最有特色的功能是處理表關聯關係非常簡單。另外 NotORM 的效能非常的高,設定高過內建的驅動。
連線資料庫
include "NotORM.php"; $pdo = new PDO("mysql:dbname=software"); $db = new NotORM($pdo);
讀取資料
foreach ($db->application() as $application) { // get all applications echo "$application[title]\n"; // print application title }
條件查詢
處理表關聯
$applications = $db->application() ->select("id, title") ->where("web LIKE ?", "http://%") ->order("title") ->limit(10) ; foreach ($applications as $id => $application) { echo "$application[title]\n"; }
JOIN共同查詢
$application = $db->application[1]; // get by primary key $application = $db->application("title = ?", "Adminer")->fetch();
結果集分組
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 }
完整範例
// get all applications ordered by author's name foreach ($db->application()->order("author.name") as $application) { echo $application->author["name"] . ": $application[title]\n"; }