コード例 #1
0
ファイル: DataSource.php プロジェクト: NareshChennuri/pyng
 /**
  * Create an instance of JO_Db_Adapter_Abstract.
  *
  * @param array $server master (supplier) or slave (consumer)
  * @return JO_Db_Adapter_Abstract|false
  * @see JO_Db
  */
 public function createConnection($server)
 {
     $config = $this->getConfig();
     foreach ($config as $key => $value) {
         if ('servers' !== $key && !array_key_exists($key, $server)) {
             $server[$key] = $value;
         }
     }
     $db = JO_Db::factory($config['adapter'], $server);
     if ($this->isConnected($db)) {
         return $db;
     }
     return false;
 }
コード例 #2
0
ファイル: IndexController.php プロジェクト: noikiy/PD
 public function indexAction()
 {
     $request = $this->getRequest();
     $this->view->msg_error = array();
     $this->view->msg_success = array();
     //begin updater
     $sys_config = APPLICATION_PATH . '/config/config_db.ini';
     if (!file_exists($sys_config)) {
         $this->view->msg_error['old_sys'] = 'System Db config file not found: <strong>' . $sys_config . '</strong>';
     } elseif (!is_writable($sys_config)) {
         $this->view->msg_error['old_sys'] = '<strong>' . $sys_config . '</strong> must be writable!';
     }
     $upload_folder = BASE_PATH . '/uploads/';
     if (!is_writable($upload_folder)) {
         $this->view->msg_error['upload'] = '<strong>' . $upload_folder . '</strong> must be writable!';
     }
     $upload_folder = BASE_PATH . '/cache/';
     if (!is_writable($upload_folder)) {
         $this->view->msg_error['cache'] = '<strong>' . $upload_folder . '</strong> must be writable!';
     }
     if (!$this->view->msg_error && $request->getPost('install') == 'yes') {
         $db_params = $request->getPost('params');
         $db_params['charset'] = 'utf8';
         foreach ($db_params as $key => $value) {
             if (!$value && in_array($key, array('password', 'dbname'))) {
                 $db_params[$key] = ' ';
             }
         }
         $error = false;
         try {
             $db = JO_Db::factory("MYSQLi", $db_params);
             $db->query("ALTER DATABASE `" . $request->getPost('params[dbname]') . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
             $db->query("SET NAMES 'utf8'");
         } catch (JO_Db_Exception $e) {
             $error = $e->getMessage();
         }
         if ($db->isConnected()) {
             if (trim($request->getPost('username')) == '') {
                 $this->view->msg_error['username'] = '******';
             } elseif (!preg_match('/^[a-zA-Z0-9_]+$/i', $request->getPost('username'))) {
                 $this->view->msg_error['username'] = '******';
             }
             if (trim($request->getPost('password')) == '') {
                 $this->view->msg_error['password'] = '******';
             }
             if (trim($request->getPost('admin_mail')) == '') {
                 $this->view->msg_error['admin_mail'] = 'You must type your email';
             } elseif (!self::ValidMail($request->getPost('admin_mail'))) {
                 $this->view->msg_error['admin_mail'] = 'You must type valid email';
             }
             if (trim($request->getPost('report_mail')) == '') {
                 $this->view->msg_error['report_mail'] = 'You must type your email';
             } elseif (!self::ValidMail($request->getPost('report_mail'))) {
                 $this->view->msg_error['report_mail'] = 'You must type valid email';
             }
             if (count($this->view->msg_error) == 0) {
                 if ($request->getPost('demo') == 'yes') {
                     $result = Model_Install::installWithDemo($db);
                 } else {
                     $result = Model_Install::installWithoutDemo($db);
                 }
                 if ($result) {
                     JO_Action::getInstance()->redirect($request->getBaseUrl() . '?module=install&action=success');
                 } else {
                     $this->view->msg_error['install_error'] = 'An error occurred during installation. Try again to install and the installation fails, contact <a target="_blank" title="marketplace script" href="http://cloneforest.com"> Marketplace script </a>';
                 }
             }
         } else {
             $this->view->msg_error['db_connect'] = $error;
         }
     }
 }
コード例 #3
0
ファイル: Application.php プロジェクト: noikiy/amatteur
 /**
  * Set Db configuration settings
  *
  * @param  array $options
  * @return JO_Db
  */
 public function setDb($options)
 {
     $adapter = null;
     if (!isset($options['adapter'])) {
         throw new JO_Exception("Db adapter not set");
     } elseif (empty($options['adapter'])) {
         throw new JO_Exception("Db adapter is empty");
     }
     if (!isset($options['params']) || !is_array($options['params'])) {
         throw new JO_Exception("Db params error");
     }
     $this->_db = JO_Db_Table::setDefaultAdapter(JO_Db::factory($options['adapter'], $options['params']));
     return $this->_db;
 }