NotORM (php orm framework) sample code-PHP source code

Source: Internet
Author: User
0

1.[Code]Connect to database

include "NotORM.php";$pdo = new PDO("mysql:dbname=software");$db = new NotORM($pdo);


2. [Code]Read Data
foreach ($db->application() as $application) { // get all applications    echo "$application[title]\n"; // print application title}


3. [Code]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";}


4. [Code]Read results
$application = $db->application[1]; // get by primary key$application = $db->application("title = ?", "Adminer")->fetch();


5. [Code]Process Table Association
echo $application->author["name"] . "\n"; // get name of the application authorforeach ($application->application_tag() as $application_tag) { // get all tags of $application    echo $application_tag->tag["name"] . "\n"; // print the tag name}


6. [Code]JOIN query

// get all applications ordered by author's nameforeach ($db->application()->order("author.name") as $application) {    echo $application->author["name"] . ": $application[title]\n";}


7. [Code]Result set group
echo $db->application()->max("id"); // get maximum IDforeach ($db->application() as $application) {    // get count of each application's tags    echo $application->application_tag()->count("*") . "\n";}


8. [Code]Complete example

 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    }}?>

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.