configure() public static method

Pass configuration settings to the class in the form of key/value pairs. As a shortcut, if the second argument is omitted and the key is a string, the setting is assumed to be the DSN string used by PDO to connect to the database (often, this will be the only configuration required to use Idiorm). If you have more than one setting you wish to configure, another shortcut is to pass an array of settings (and omit the second argument).
public static configure ( string $key, mixed $value = null, string $connection_name = self::DEFAULT_CONNECTION )
$key string
$value mixed
$connection_name string Which connection to use
Ejemplo n.º 1
1
 /**
  * When creating the model, the configs for database connection creation are needed
  * @param $config
  */
 public function __construct($config)
 {
     //ORM::configure('logging', true);
     ORM::configure("mysql:host={$config['db_host']};dbname={$config['db_name']};port={$config['db_port']};charset=utf8");
     ORM::configure('username', $config['db_user']);
     ORM::configure('password', $config['db_pass']);
 }
Ejemplo n.º 2
0
 /**
  * Set the database name, username and password
  */
 function configureDb($database, $username, $password)
 {
     \ORM::configure("mysql:host=localhost;dbname={$database};charset=utf8mb4");
     \ORM::configure('username', $username);
     \ORM::configure('password', $password);
     $this->config->set("data.dbName", $database);
 }
Ejemplo n.º 3
0
 public function __construct()
 {
     require 'idiorm.php';
     ORM::configure('mysql:host=localhost;dbname=etutor');
     ORM::configure('username', 'root');
     ORM::configure('password', 'pass');
 }
Ejemplo n.º 4
0
function dbInsert($row, $user)
{
    ORM::configure(array('connection_string' => 'mysql:host=localhost;dbname=qiita', 'username' => 'xxxx', 'password' => 'xxxx', 'driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), 'error_mode', PDO::ERRMODE_WARNING, 'logging', true));
    //記事登録
    $items = ORM::for_table('items')->where_equal('item_id', $row['item_id'])->find_one();
    if (!$items) {
        //未登録の記事は登録
        $items = ORM::for_table('items')->create();
        $items->set($row);
        $items->save();
    }
    //ユーザ情報登録
    $users = ORM::for_table('users')->where_equal('user_id', $user['user_id'])->find_one();
    print_r($user);
    echo $user['user_id'];
    if (!$users) {
        //未登録のユーザは登録
        $users = ORM::for_table('users')->create();
        $users->set($user);
        echo " 登録<br>";
    } else {
        //登録済のユーザは更新
        $users->set($user);
        echo " 更新<br>";
    }
    $users->save();
}
Ejemplo n.º 5
0
 private function idiorm($path)
 {
     if (!mapi_include_abs_path($path, 'lib')) {
         return null;
     }
     if (!isset(MSettings::$db_host) || !strlen(MSettings::$db_host) > 0) {
         return false;
     }
     if (!isset(MSettings::$db) || !strlen(MSettings::$db) > 0) {
         return false;
     }
     if (!isset(MSettings::$db_user) || !strlen(MSettings::$db_user) > 0) {
         return false;
     }
     if (!isset(MSettings::$db_pass) || !strlen(MSettings::$db_pass) > 0) {
         return false;
     }
     try {
         ORM::configure('mysql:host=' . MSettings::$db_host . ';dbname=' . MSettings::$db);
         ORM::configure('username', MSettings::$db_user);
         ORM::configure('password', MSettings::$db_pass);
         ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
         $test = ORM::for_table('preferences')->create();
         if ($test) {
             return true;
         } else {
             return false;
         }
     } catch (PDOException $e) {
         return false;
     }
 }
Ejemplo n.º 6
0
 /**
  * Create POST route for updating a row
  */
 protected function updateRowRoute()
 {
     // Save Model
     $this->app->post('/{table}/save', function ($request, $response, $args) {
         $newResponse = $response->withHeader('Content-type', 'application/json');
         try {
             // Get primary key of table from response
             $primary_key = $request->getParam('primary_key');
             // Get primary key value of this model from response
             $primary_key_value = $request->getParam('params')[$primary_key];
             // Set table's primary key for saving model
             ORM::configure('id_column_overrides', array($args['table'] => $primary_key));
             // Create model from query, set new parameters, and save it
             $model = ORM::for_table($args['table'])->where($primary_key, intval(6))->find_many()[0];
             $model->set($request->getParam('params'));
             $success = $model->save();
             $response_body = array("success" => $success);
         } catch (Exception $e) {
             error_log(ORM::get_last_statement()->queryString);
             error_log($e->getMessage());
             $response_body = array("error" => $e->getMessage());
         }
         // Add data to response in JSON format
         $newResponse->write(json_encode($response_body));
         return $newResponse;
     });
 }
Ejemplo n.º 7
0
 public function tearDown()
 {
     ORM::configure('logging', false);
     ORM::configure('logging', false, self::ALTERNATE);
     ORM::set_db(null);
     ORM::set_db(null, self::ALTERNATE);
 }
Ejemplo n.º 8
0
 public function __construct()
 {
     \ORM::configure('mysql:host=localhost;dbname=igorpronin_list');
     \ORM::configure('username', 'igorpronin_list');
     \ORM::configure('password', '');
     //todo скрыть при размещении на github
 }
Ejemplo n.º 9
0
function connect()
{
    ORM::configure('mysql:host=localhost;dbname=fake');
    ORM::configure('username', 'root');
    ORM::configure('password', 'root');
    ORM::configure('error_mode', PDO::ERRMODE_WARNING);
}
Ejemplo n.º 10
0
 public function __construct()
 {
     ORM::configure('mysql:host=localhost;dbname=loft_shop');
     ORM::configure('username', 'root');
     ORM::configure('password', '');
     ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
     ORM::configure('id_column_overrides', array('user_group' => array('id_user', 'id_group')));
 }
Ejemplo n.º 11
0
function connect()
{
    ORM::configure('mysql:host=localhost;dbname=crm');
    ORM::configure('username', 'root');
    ORM::configure('password', 'MOTDEPASSE');
    ORM::configure('error_mode', PDO::ERRMODE_WARNING);
    ORM::configure('return_result_sets', true);
}
Ejemplo n.º 12
0
function database()
{
    ORM::configure('mysql:host=localhost;dbname=fake');
    ORM::configure('username', 'root');
    ORM::configure('password', 'root');
    ORM::configure('error_mode', PDO::ERRMODE_WARNING);
    ORM::configure('return_result_sets', true);
}
Ejemplo n.º 13
0
 protected function connect()
 {
     ORM::configure('mysql:host=' . $this->config["db"]["host"] . ";dbname=" . $this->config["db"]["dbname"]);
     ORM::configure('username', $this->config["db"]["username"]);
     ORM::configure('password', $this->config["db"]["password"]);
     ORM::configure('error_mode', PDO::ERRMODE_WARNING);
     ORM::configure('return_result_sets', true);
 }
Ejemplo n.º 14
0
    public function run()
    {
        $spider_name = isset($_REQUEST['spider']) ? $_REQUEST['spider'] : '';
        $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
        $title = 'Spider';
        $spider = $this->get_spider($spider_name);
        if ($spider) {
            $title = $spider->get_title();
            // DB
            $dbpath = $spider->get_db_path();
            $empty_database = false;
            if (!is_file($dbpath)) {
                touch($dbpath);
                $empty_database = true;
            }
            $dbpath = realpath($dbpath);
            ORM::configure('sqlite:' . $dbpath);
            if ($empty_database) {
                $spider->create_database();
            }
        }
        // header
        include '_header.php';
        // loaded with bootstrap
        // process
        ?>
		<ul class="nav nav-tabs">
			<?php 
        $this->print_menu('Fakku');
        ?>
			<?php 
        $this->print_menu('Hbrowse');
        ?>
			<?php 
        $this->print_menu('HentaiMangaOnline');
        ?>
			<?php 
        $this->print_menu('FreeHManga');
        ?>
		</ul>
		<div class="container">
	<?php 
        if ($spider) {
            $method = 'action_' . $action;
            if (method_exists($spider, $method)) {
                $spider->{$method}();
            } else {
                echo 'Choose something';
            }
        } else {
            echo 'Select Spider';
        }
        ?>
		</div>
	<?php 
        // footer
        include '_footer.php';
    }
Ejemplo n.º 15
0
 public function setUp()
 {
     // Enable logging
     ORM::configure('logging', true);
     ORM::configure('caching', false);
     // Set up the dummy database connection
     $db = new DummyPDO('sqlite::memory:');
     ORM::setDatabase($db);
 }
Ejemplo n.º 16
0
 public function __construct()
 {
     // Open the database connection with the credentials from application/config/config.php
     // generate a database connection, using the PDO connector
     // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
     ORM::configure(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME);
     ORM::configure('username', DB_USER);
     ORM::configure('password', DB_PASS);
 }
Ejemplo n.º 17
0
 private function setupDatabase()
 {
     $config =& $this->config;
     $hostname = $config['database']['hostname'];
     $database = $config['database']['database'];
     $username = $config['database']['username'];
     $password = $config['database']['password'];
     $dsn = "mysql:host={$hostname};dbname={$database}";
     \ORM::configure(array("connection_string" => $dsn, 'username' => $username, 'password' => $password));
 }
Ejemplo n.º 18
0
 /**
  * Configure ORM
  */
 public function __construct()
 {
     global $IMC;
     \ORM::configure('mysql:host=' . $IMC['dbhost'] . ';port=' . $IMC['dbport'] . ';dbname=' . $IMC['dbname']);
     \ORM::configure('username', $IMC['dbuser']);
     \ORM::configure('password', $IMC['dbpassword']);
     \ORM::configure('logging', true);
     \ORM::configure('return_result_sets', true);
     \ORM::configure('driver_options', array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
 }
Ejemplo n.º 19
0
 public function __construct()
 {
     \ORM::configure(sprintf("mysql:host=%s;charset=utf8;dbname=%s", DB_HOSTNAME, DB_DATABASE));
     \ORM::configure('username', DB_USERNAME);
     \ORM::configure('password', DB_PASSWORD);
     \ORM::configure('return_result_sets', true);
     \ORM::configure('logging', defined('ENVIRONMENT') && ENVIRONMENT == 'dev');
     \ORM::configure('id_column', $this->id_field);
     $this->set_prefixes();
 }
Ejemplo n.º 20
0
function database_start()
{
    $config = \App\Config::getInstance()->get('database');
    switch (strtolower($config['active'])) {
        case 'mysql':
            ORM::configure(sprintf('mysql:host=%s;dbname=%s', $config['mysql']['hostname'], $config['mysql']['name']));
            ORM::configure('username', $config['mysql']['username']);
            ORM::configure('password', $config['mysql']['password']);
    }
}
Ejemplo n.º 21
0
 public static function get()
 {
     $data = array();
     ORM::configure('id_column', self::$table . 'Id');
     $d = self::set_query()->find_many();
     self::clear_query();
     foreach ($d as $key => $row) {
         $data[] = static::_format_get($row->as_array());
     }
     return $data;
 }
 public function register(Application $app)
 {
     $app['paris'] = $app->share(function () use($app) {
         \ORM::configure($app['paris.dsn']);
         \ORM::configure('username', $app['paris.username']);
         \ORM::configure('password', $app['paris.password']);
         \ORM::configure('logging', true);
         \ORM::configure('driver_options', array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
         return new ParisWrapper();
     });
 }
Ejemplo n.º 23
0
 public function __construct($conf)
 {
     self::$prefix = $conf['prefix'];
     if ($conf['driver'] == 'sqlite') {
         \ORM::configure(sprintf('sqlite:%s', $conf['dbname']));
     } else {
         \ORM::configure($conf['driver'] . ':host=' . $conf['host'] . ';dbname=' . $conf['dbname']);
         \ORM::configure('username', $conf['user']);
         \ORM::configure('password', $conf['password']);
     }
 }
Ejemplo n.º 24
0
 public function configureDatabase()
 {
     $host = $this->get('database_host');
     $databaseName = $this->get('database_name');
     $databaseUser = $this->get('database_user');
     $databasePassword = $this->get('database_password');
     ORM::configure("mysql:host={$host};dbname={$databaseName}");
     ORM::configure('username', $databaseUser);
     ORM::configure('password', $databasePassword);
     ORM::configure('id_column_overrides', array('insightengine_tags' => 'tag_id'));
 }
Ejemplo n.º 25
0
 public function setUp()
 {
     \ORM::configure('mysql:dbname=simple-quiz;host=localhost');
     \ORM::configure('username', 'travis');
     \ORM::configure('password', '');
     \ORM::configure('return_result_sets', true);
     $this->app = new Set();
     $this->app->leaderboard = function () {
         return new LeaderBoard();
     };
     $this->quiz = new Quiz($this->app);
 }
Ejemplo n.º 26
0
 /**
  * DBの設定を行う
  */
 protected function setDatabase()
 {
     // Idiorm(ORM)
     \ORM::configure($this->config('db_host') . $this->config('db_name'));
     \ORM::configure('username', $this->config('db_user'));
     \ORM::configure('password', $this->config('db_password'));
     if (!empty($this->config('db_options'))) {
         \ORM::configure('driver_options', $this->config('db_options'));
     }
     \ORM::configure('error_mode', $this->config('db_error_mode'));
     \ORM::configure('logging', true);
 }
Ejemplo n.º 27
0
 public function setDB($config)
 {
     foreach ($config as $name => $option) {
         if (Registry::getInstance()->debug) {
             $option['logging'] = true;
             \ORM::configure('logger', function ($query, $time) {
                 Model::logging($query, $time);
             }, $name);
         }
         \ORM::configure($option, null, $name);
     }
 }
Ejemplo n.º 28
0
 public function __construct($config = array(), $params = array(), $path = array())
 {
     $path = array_merge($path, array(__DIR__ . '/../../../../src/templates', __DIR__ . '/../error'));
     $this->params = $params;
     $this->loader = new \Twig_Loader_Filesystem($path);
     $this->twig = new \Twig_Environment($this->loader, array('cache' => false, 'debug' => true));
     $this->twig->addExtension(new \Twig_Extension_Debug());
     if (isset($config['database'])) {
         \ORM::configure('mysql:host=' . $config['database']['host'] . ';dbname=' . $config['database']['name']);
         \ORM::configure('username', $config['database']['user']);
         \ORM::configure('password', $config['database']['password']);
     }
 }
function fixeddigital_by_suburb($suburb)
{
    header('content-type: text/plain');
    require_once 'lib/idiorm.php';
    $databaseName = "govhack15";
    ORM::configure("mysql:host=mysql02.c7vaazdx09rf.ap-southeast-2.rds.amazonaws.com;dbname={$databaseName}");
    ORM::configure('username', 'ben');
    ORM::configure('password', 'Password1');
    $thisMonthName = date('M');
    $thisFY = '2013/14';
    // echo 'FixedDigital by '.$suburb, PHP_EOL;
    // echo 'MonthName is '.$thisMonthName, PHP_EOL;
    $qHasSchoolZones = ORM::for_table('fixed_digital')->distinct()->select('zone_type')->where_like('auspost_suburb', "%{$suburb}%")->where('zone_type', 'School Zone')->find_one();
    $qNumFinesThisYear = ORM::for_table('fixed_digital')->select_expr('SUM(total_fines)', 'total_suburb_fines')->where_like('auspost_suburb', "%{$suburb}%")->where('fy', $thisFY)->find_one();
    $qAvgOffencesPerMonth = ORM::for_table('fixed_digital')->select('month')->select_expr('SUM(total_fines)', 'total_suburb_fines')->where_like('auspost_suburb', "%{$suburb}%")->group_by('month')->group_by('auspost_suburb')->order_by_desc('total_suburb_fines')->find_many();
    $qAvgOffencesThisMonth = ORM::for_table('fixed_digital')->select_expr('SUM(total_fines)', 'total_suburb_fines')->where_like('auspost_suburb', "%{$suburb}%")->where('month', $thisMonthName)->group_by('fy')->find_many();
    $qAvgPenaltyAmount = ORM::for_table('fixed_digital')->select_expr('SUM(total_dollars)', 'total_suburb_dollars')->select_expr('SUM(total_fines)', 'total_suburb_fines')->where_like('auspost_suburb', "%{$suburb}%")->group_by('auspost_suburb')->find_one();
    $qAvgRevenueThisMonth = ORM::for_table('fixed_digital')->select_expr('SUM(total_dollars)', 'total_suburb_dollars')->where_like('auspost_suburb', "%{$suburb}%")->where('month', $thisMonthName)->where('fy', $thisFY)->find_one();
    $qMostCommonBand = ORM::for_table('fixed_digital')->select_expr('COUNT(speed_band)', 'total_suburb_speedband')->select('speed_band')->where_like('auspost_suburb', "%{$suburb}%")->group_by('speed_band')->order_by_desc('total_suburb_speedband')->find_one();
    // if hasSchoolZones
    $hasSchoolZones = false;
    if ($qHasSchoolZones && sizeof($qHasSchoolZones) > 0) {
        $hasSchoolZones = true;
    }
    // Calculate avg offences per month
    $sum = 0;
    $thisMonthRank = 0;
    foreach ($qAvgOffencesPerMonth as $i => $perMonth) {
        $sum += intval($perMonth->total_suburb_fines);
        if (strtolower($perMonth->month) == strtolower($thisMonthName)) {
            $thisMonthRank = $i + 1;
        }
    }
    $avgOffencesPerMonth = 0;
    if (sizeof($qAvgOffencesPerMonth) > 0) {
        $avgOffencesPerMonth = $sum / sizeof($qAvgOffencesPerMonth);
    }
    // Calculate avg offences this month
    $sum = 0;
    foreach ($qAvgOffencesThisMonth as $perMonth) {
        $sum += intval($perMonth->total_suburb_fines);
    }
    $avgOffencesThisMonth = 0;
    if (sizeof($qAvgOffencesThisMonth)) {
        $avgOffencesThisMonth = $sum / sizeof($qAvgOffencesThisMonth);
    }
    $avgPenaltyAmount = $qAvgPenaltyAmount && intval($qAvgPenaltyAmount->total_suburb_fines) > 0 ? intval($qAvgPenaltyAmount->total_suburb_dollars) / intval($qAvgPenaltyAmount->total_suburb_fines) : 0;
    return array('is_top_twenty' => false, 'has_school_zones' => $hasSchoolZones, 'num_offences_this_year' => $qNumFinesThisYear->total_suburb_fines, 'avg_offences_per_month' => $avgOffencesPerMonth, 'avg_offences_this_month' => $avgOffencesThisMonth, 'avg_penalty_amount' => $avgPenaltyAmount, 'most_common_band' => $qMostCommonBand ? $qMostCommonBand->speed_band : 0, 'total_revenue_this_month' => $qAvgRevenueThisMonth->total_suburb_dollars, 'this_month_rank' => $thisMonthRank);
}
Ejemplo n.º 30
0
function db_init()
{
    $functestFile = pref_getSectionPreference('functest', 'functestLockFile');
    if ($functestFile && file_exists($functestFile)) {
        $dsn = pref_getSectionPreference('functest', 'functestDatabase');
    } else {
        $dsn = pref_getServerPreference('database');
    }
    $parts = db_splitDsn($dsn);
    ORM::configure(sprintf("mysql:host=%s;dbname=%s", $parts['host'], $parts['database']));
    ORM::configure('username', $parts['user']);
    ORM::configure('password', $parts['password']);
    // If you enable query logging, you can then run var_dump(ORM::get_query_log());
    // ORM::configure('logging', true);
    ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
}