当前位置: 首页>>代码示例>>PHP>>正文


PHP ORM::getDb方法代码示例

本文整理汇总了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;
}
开发者ID:kevinsperrine,项目名称:idiorm,代码行数:31,代码来源:demo.php

示例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']]];
开发者ID:dev-lucid,项目名称:lucid,代码行数:4,代码来源:phinx.php


注:本文中的ORM::getDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。