本文整理汇总了PHP中ORM::getDb方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::getDb方法的具体用法?PHP ORM::getDb怎么用?PHP ORM::getDb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ORM
的用法示例。
在下文中一共展示了ORM::getDb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: contact
<?php
// ------------------- //
// --- Idiorm Demo --- //
// ------------------- //
// Note: This is just about the simplest database-driven webapp it's possible to create
// and is designed only for the purpose of demonstrating how Idiorm works.
// In case it's not obvious: this is not the correct way to build web applications!
// Require the idiorm file
require_once "Idiorm.php";
// Connect to the demo database file
ORM::configure('sqlite:./demo.sqlite');
// This grabs the raw database connection from the ORM
// class and creates the table if it doesn't already exist.
// Wouldn't normally be needed if the table is already there.
$db = ORM::getDb();
$db->exec("\n CREATE TABLE IF NOT EXISTS contact (\n id INTEGER PRIMARY KEY, \n name TEXT, \n email TEXT \n );");
// Handle POST submission
if (!empty($_POST)) {
// Create a new contact object
$contact = ORM::forTable('contact')->create();
// SHOULD BE MORE ERROR CHECKING HERE!
// Set the properties of the object
$contact->name = $_POST['name'];
$contact->email = $_POST['email'];
// Save the object to the database
$contact->save();
// Redirect to self.
header('Location: ' . basename(__FILE__));
exit;
}
示例2:
<?php
include __DIR__ . '/../bootstrap.php';
return ["paths" => ["migrations" => __DIR__ . "/../dataase/migrations/", "seeds" => __DIR__ . "/../database/migrations/"], "environments" => ["default_migration_table" => "phinxlog", "default_database" => "development", "development" => ['connection' => \ORM::getDb(), 'name' => 'development'], "qa" => ['connection' => \ORM::getDb(), 'name' => 'qa'], "production" => ['connection' => \ORM::getDb(), 'name' => 'production']]];