set_db() public static méthode

This is public in case the ORM should use a ready-instantiated PDO object as its database connection. Accepts an optional string key to identify the connection if multiple connections are used.
public static set_db ( PDO $db, string $connection_name = self::DEFAULT_CONNECTION )
$db PDO
$connection_name string Which connection to use
 public function tearDown()
 {
     ORM::configure('logging', false);
     ORM::configure('logging', false, self::ALTERNATE);
     ORM::set_db(null);
     ORM::set_db(null, self::ALTERNATE);
 }
Exemple #2
0
 public function setup_db()
 {
     $settings = $this->get_setting("db");
     if (isset($settings['socket']) && strlen($settings['socket']) > 2) {
         $dsn = "{$settings['type']}:unix_socket={$settings['socket']};dbname={$settings['name']}";
     } else {
         $dsn = "{$settings['type']}:host={$settings['host']};port={$settings['port']};dbname={$settings['name']}";
     }
     $driver_command = array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION sql_mode='TRADITIONAL'");
     $db = new \PDO($dsn, $settings["username"], $settings["password"], $driver_command);
     $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     self::$db = $db;
     if (isset($settings['table'])) {
         $this->table = $settings['table'];
     }
     if (isset($settings['primary_key'])) {
         $this->primary_key = $settings['primary_key'];
     }
     $query["logging"] = true;
     Query::set_db($db);
     Query::configure($query);
 }
Exemple #3
0
 * Basic testing for Dakota.
 *
 * We deliberately don't test the query API - that's Idiorm's job.
 * We just test Paris-specific functionality.
 *
 * Checks that the generated SQL is correct
 *
 */
require_once dirname(__FILE__) . "/idiorm.php";
require_once dirname(__FILE__) . "/../dakota.php";
require_once dirname(__FILE__) . "/test_classes.php";
// Enable logging
ORM::configure('logging', true);
// Set up the dummy database connection
$db = new DummyPDO('sqlite::memory:');
ORM::set_db($db);
class Simple extends Model
{
}
Model::factory('Simple')->find_many();
$expected = 'SELECT * FROM `simple`';
Tester::check_query("Simple auto table name", $expected);
class ComplexModelClassName extends Model
{
}
Model::factory('ComplexModelClassName')->find_many();
$expected = 'SELECT * FROM `complex_model_class_name`';
Tester::check_query("Complex auto table name", $expected);
class ModelWithCustomTable extends Model
{
    public static $_table = 'custom_table';
 public function tearDown()
 {
     ORM::configure('logging', false);
     ORM::set_db(null);
     Model::$auto_prefix_models = null;
 }
Exemple #5
0
 public function tearDown()
 {
     ORM::configure('logging', false);
     ORM::set_db(null);
 }
Exemple #6
0
<?php

// composer
$composer_autoload_file = __DIR__ . '/vendor/autoload.php';
if (!file_exists($composer_autoload_file)) {
    throw new Exception('You need to run "composer install"!');
}
require_once __DIR__ . '/vendor/autoload.php';
// models
require_once __DIR__ . '/models.php';
// db & sess
$pdo = new PDO('mysql:host=localhost;dbname=crudexample;charset=utf8', 'root', 'root');
ORM::set_db($pdo);
session_start();