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
コード例 #1
1
ファイル: entities.php プロジェクト: harshid86/QuizExample
 /**
  * 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']);
 }
コード例 #2
0
ファイル: Abode.php プロジェクト: NeonPaul/abode
 /**
  * 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);
 }
コード例 #3
0
ファイル: chapter.php プロジェクト: sooraj007/etutor
 public function __construct()
 {
     require 'idiorm.php';
     ORM::configure('mysql:host=localhost;dbname=etutor');
     ORM::configure('username', 'root');
     ORM::configure('password', 'pass');
 }
コード例 #4
0
ファイル: index.php プロジェクト: bzz0217/qiita_items
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();
}
コード例 #5
0
ファイル: libraries.php プロジェクト: adncentral/mapi-geoCMS
 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;
     }
 }
コード例 #6
0
ファイル: Qbuild.php プロジェクト: gholme4/Qbuild
 /**
  * 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;
     });
 }
コード例 #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);
 }
コード例 #8
0
 public function __construct()
 {
     \ORM::configure('mysql:host=localhost;dbname=igorpronin_list');
     \ORM::configure('username', 'igorpronin_list');
     \ORM::configure('password', '');
     //todo скрыть при размещении на github
 }
コード例 #9
0
ファイル: functions.php プロジェクト: SimplonTlse/MiniCRM
function connect()
{
    ORM::configure('mysql:host=localhost;dbname=fake');
    ORM::configure('username', 'root');
    ORM::configure('password', 'root');
    ORM::configure('error_mode', PDO::ERRMODE_WARNING);
}
コード例 #10
0
ファイル: model.php プロジェクト: Antoshka007/php_dz5
 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')));
 }
コード例 #11
0
ファイル: functions.php プロジェクト: nemo75/sql
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);
}
コード例 #12
0
ファイル: function.php プロジェクト: AmbreB/ExercicesSimplon
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);
}
コード例 #13
0
ファイル: Model.php プロジェクト: AmbreB/Senny
 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);
 }
コード例 #14
0
ファイル: spider.php プロジェクト: JerryMaheswara/crawler
    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';
    }
コード例 #15
0
ファイル: ModelTest.php プロジェクト: kevinsperrine/paris
 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);
 }
コード例 #16
0
ファイル: controller.php プロジェクト: imjching/php-skeleton
 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);
 }
コード例 #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));
 }
コード例 #18
0
ファイル: Model.php プロジェクト: vanloswang/webim-for-php5
 /**
  * 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'));
 }
コード例 #19
0
ファイル: Base.php プロジェクト: ayvanov/magok-parser
 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();
 }
コード例 #20
0
ファイル: database.php プロジェクト: signalfire/whatblog
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']);
    }
}
コード例 #21
0
ファイル: Model.php プロジェクト: cloudmanic/cloudmanic-cms
 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;
 }
コード例 #22
0
 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();
     });
 }
コード例 #23
0
ファイル: Connection.php プロジェクト: nikrou/demoBehatTravis
 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']);
     }
 }
コード例 #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'));
 }
コード例 #25
0
ファイル: QuizTest.php プロジェクト: purdel/simple-quiz
 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);
 }
コード例 #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);
 }
コード例 #27
0
ファイル: App.php プロジェクト: higherchen/pikachu
 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);
     }
 }
コード例 #28
0
ファイル: Twiger.php プロジェクト: purplebabar/twiger-core
 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']);
     }
 }
コード例 #29
0
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);
}
コード例 #30
0
ファイル: db.php プロジェクト: nastasie-octavian/DEXonline
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'));
}