首頁  >  文章  >  php教程  >  php NotORM(PHP的ORM框架)範例程式碼

php NotORM(PHP的ORM框架)範例程式碼

大家讲道理
大家讲道理原創
2016-11-08 14:14:181367瀏覽

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";
}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn