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. ...