Example #1
0
 protected function loadProfiles()
 {
     $file = jApp::configPath('profiles.ini.php');
     if (file_exists($file)) {
     } elseif (file_exists(jApp::configPath('profiles.ini.php.dist'))) {
         copy(jApp::configPath('profiles.ini.php.dist'), $file);
     } else {
         file_put_contents($file, ";<?php die(''); ?>\n;for security reasons, don't remove or modify the first line\n\n[jdb:default]\ndriver=mysqli\ndatabase=\nhost=localhost\nuser=\npassword=\npersistent = on\nforce_encoding = on\ntable_prefix=\n");
     }
     $ini = new \Jelix\IniFile\IniModifier($file);
     $data = array('dbtype' => array(), 'driver' => array(), 'database' => array(), 'host' => array(), 'port' => array(), 'user' => array(), 'password' => array(), 'passwordconfirm' => array(), 'persistent' => array(), 'table_prefix' => array(), 'force_encoding' => array(), 'search_path' => array(), 'errors' => array());
     $profiles = $ini->getSectionList();
     $dbprofileslist = array();
     foreach ($profiles as $profile) {
         if (strpos($profile, 'jdb:') !== 0) {
             continue;
         }
         $dbprofileslist[] = $profile;
         $options = $ini->getValues($profile);
         $dbparam = new jDbParameters($options);
         $options = $dbparam->getParameters();
         $data['dbtype'][$profile] = $options['dbtype'];
         $driver = $options['driver'];
         if ($options['usepdo']) {
             $dsn = $ini->getValue('dsn', $profile);
             $data['driver'][$profile] = $driver . ':pdo';
             if (preg_match("/host=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['host'][$profile] = $m[1];
             } else {
                 $host = $ini->getValue('host', $profile);
                 $data['host'][$profile] = $host === null ? '' : $host;
             }
             if (preg_match("/dbname=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['database'][$profile] = $m[1];
             } else {
                 $host = $ini->getValue('database', $profile);
                 $data['database'][$profile] = $host === null ? '' : $host;
             }
             if (preg_match("/port=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['port'][$profile] = $m[1];
             } else {
                 $port = $ini->getValue('port', $profile);
                 $data['port'][$profile] = $port === null ? '' : $port;
             }
         } else {
             $data['driver'][$profile] = $driver . ($options['usepdo'] ? ':pdo' : '');
             $data['database'][$profile] = $ini->getValue('database', $profile);
             $data['host'][$profile] = $ini->getValue('host', $profile);
             $data['port'][$profile] = $ini->getValue('port', $profile);
         }
         $data['user'][$profile] = $ini->getValue('user', $profile);
         $data['password'][$profile] = $ini->getValue('password', $profile);
         $data['passwordconfirm'][$profile] = $data['password'][$profile];
         $data['persistent'][$profile] = $options['persistent'];
         $data['force_encoding'][$profile] = $options['force_encoding'];
         $data['table_prefix'][$profile] = $ini->getValue('table_prefix', $profile);
         $data['search_path'][$profile] = $ini->getValue('search_path', $profile);
         $data['errors'][$profile] = array();
     }
     $_SESSION['dbprofiles']['profiles'] = $dbprofileslist;
     $_SESSION['dbprofiles']['data'] = $data;
 }
Example #2
0
 protected function consolidate($profile)
 {
     $parameters = new jDbParameters($profile);
     return $parameters->getParameters();
 }