Notorm (PHP ORM Framework) sample Code _php Tutorial

Source: Internet
Author: User
In the Fire download section, we released the Notorm, a completely free PHP library to simplify and interact with the database. The most distinctive feature is that it is very easy to handle the table association relationship. In addition Notorm performance is very high, set high over the built-in driver.

Let's look at some of the Notorm sample code below:

To connect to a database:

Copy to ClipboardWhat to refer to: [www.bkjia.com]Include "notorm.php";
$pdo = new PDO ("Mysql:dbname=software");
$db = new Notorm ($PDO);

Read data:

Copy to ClipboardWhat to refer to: [www.bkjia.com]foreach ($db->application () as $application) {//Get all applications
echo "$application [title]\n]; Print Application Title
}

Conditional query:

Copy to ClipboardWhat to refer to: [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 Result:

Copy to ClipboardWhat to refer to: [www.bkjia.com]$application = $db->application[1]; Get by PRIMARY key
$application = $db->application ("title =?", "Adminer")->fetch ();

Working with Table associations:

Copy to ClipboardWhat to refer to: [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 UNION query:

Copy to ClipboardWhat to refer to: [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 grouping:

Copy to ClipboardWhat to refer to: [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 Example:

Copy to ClipboardWhat to refer to: [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
}
}
?>

http://www.bkjia.com/PHPjc/363954.html www.bkjia.com true http://www.bkjia.com/PHPjc/363954.html techarticle in the Fire download section, we released the Notorm, a completely free PHP library to simplify and interact with the database. The most distinctive feature is that it is very easy to handle the table association relationship. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.