Exemplo n.º 1
0
 public function testAdapterExceptionInvalidLoginCredentials()
 {
     $params = $this->_util->getParams();
     $params['password'] = '******';
     // invalid password
     try {
         $db = new Zend_Db_Adapter_Pdo_Mysql($params);
         $db->getConnection();
         // force a connection
         $this->fail('Expected to catch Zend_Db_Adapter_Exception');
     } catch (Zend_Exception $e) {
         $this->assertType('Zend_Db_Adapter_Exception', $e, 'Expecting object of type Zend_Db_Adapter_Exception, got ' . get_class($e));
     }
 }
Exemplo n.º 2
0
 public function jsonAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $db_params = OpenContext_OCConfig::get_db_config();
     $db = new Zend_Db_Adapter_Pdo_Mysql($db_params);
     $db->getConnection();
     $requestParams = $this->_request->getParams();
     $host = App_Config::getHost();
     $reference = new Reference();
     $reference->initialize($requestParams);
     if ($reference->get_refs()) {
         header('Content-Type: application/json; charset=utf8');
         //echo Zend_Json::encode($reference->placeTokens);
         echo Zend_Json::encode($reference->tmPlaces);
     } else {
         $this->view->requestURI = $this->_request->getRequestUri();
         return $this->render('404error');
     }
 }
Exemplo n.º 3
0
 private function connectDB()
 {
     try {
         $dbconfig = array('host' => $this->config->database->host, 'username' => $this->config->database->username, 'password' => $this->config->database->password, 'dbname' => $this->config->database->db);
         $dbconfig = $this->doQoolHook('front_pre_connectdb', $dbconfig);
         //here we check for database type
         switch ($this->config->database->type) {
             case "mysql":
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
                 break;
             case "sqlite":
                 $db = new Zend_Db_Adapter_Pdo_Sqlite($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 break;
             default:
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
         }
     } catch (Zend_Db_Adapter_Exception $e) {
         $this->triggerError($this->language['db_connect_error']);
     } catch (Zend_Exception $e) {
         $this->triggerError($this->language['db_factory_error']);
     }
     $db = $this->doQoolHook('front_after_connectdb', $db);
     $this->db = $db;
 }
Exemplo n.º 4
0
 try {
     $db = new Zend_Db_Adapter_Pdo_Mysql($dbConfig);
     $db->getConnection();
     // check utf-8 encoding
     $result = $db->fetchRow('SHOW VARIABLES LIKE "character\\_set\\_database"');
     if ($result['Value'] != "utf8") {
         die("Database charset is not utf-8");
     }
 } catch (Exception $e) {
     echo $e->getMessage() . "\n";
     die("Couldn't establish connection to mysql" . "\n");
 }
 $db->getConnection()->exec("DROP database IF EXISTS pimcore_phpunit;");
 $db->getConnection()->exec("CREATE DATABASE pimcore_phpunit CHARACTER SET utf8");
 $db = new Zend_Db_Adapter_Pdo_Mysql($dbConfig);
 $db->getConnection();
 $db->getConnection()->exec("SET NAMES UTF8");
 $db->getConnection()->exec("SET storage_engine=InnoDB;");
 // insert db dump
 //$db = Pimcore_Resource::get();
 $mysqlInstallScript = file_get_contents(PIMCORE_PATH . "/modules/install/mysql/install.sql");
 // remove comments in SQL script
 $mysqlInstallScript = preg_replace("/\\s*(?!<\")\\/\\*[^\\*]+\\*\\/(?!\")\\s*/", "", $mysqlInstallScript);
 // get every command as single part
 $mysqlInstallScripts = explode(";", $mysqlInstallScript);
 // execute every script with a separate call, otherwise this will end in a PDO_Exception "unbufferd queries, ..."
 foreach ($mysqlInstallScripts as $m) {
     $sql = trim($m);
     if (strlen($sql) > 0) {
         $sql .= ";";
         $db->exec($m);
Exemplo n.º 5
0
 private function connectDB()
 {
     $xml = readLangFile('config/config.xml');
     setIncludePath(array('special' => array('folder' => $xml->host->folder)));
     try {
         $dbconfig = array('host' => $xml->database->host, 'username' => $xml->database->username, 'password' => $xml->database->password, 'dbname' => $xml->database->db);
         //here we check for database type
         switch ($xml->database->type) {
             case "mysql":
                 require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
                 break;
             default:
                 require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
         }
     } catch (Zend_Db_Adapter_Exception $e) {
         $this->triggerError($this->language['db_connect_error']);
     } catch (Zend_Exception $e) {
         $this->triggerError($this->language['db_factory_error']);
     }
     $this->db = $db;
 }
    public function processAction()
    {
        $error = array();
        $defaultNamespace = new Zend_Session_Namespace('Default');
        $options = array('authentication' => array('email' => $this->getRequest()->getParam('admin_email'), 'password' => $this->getRequest()->getParam('admin_password')), 'settings' => array('default_from' => $this->getRequest()->getParam('default_from'), 'keep_history' => $this->getRequest()->getParam('keep_history'), 'alchemy_api_key' => $this->getRequest()->getParam('alchemy_api_key')), 'resources' => array('db' => array('adapter' => 'PDO_MYSQL', 'params' => array('host' => $this->getRequest()->getParam('db_host'), 'username' => $this->getRequest()->getParam('db_user'), 'password' => $this->getRequest()->getParam('db_password'), 'dbname' => $this->getRequest()->getParam('db_name'), 'prefix' => $this->getRequest()->getParam('db_prefix')))));
        $validator = new Zend_Validate_EmailAddress();
        if (!$validator->isValid($options['authentication']['email'])) {
            $error['admin_email'] = 'Administrator e-mail is invalid';
        }
        if (!trim($options['authentication']['password'])) {
            $error['admin_password'] = '******';
        }
        if (!$validator->isValid($options['settings']['default_from'])) {
            $error['default_from'] = 'Default "from" e-mail is invalid';
        }
        if (!trim($options['resources']['db']['params']['host'])) {
            $error['db_host'] = 'Database host can not be blank';
        }
        if (!trim($options['resources']['db']['params']['username'])) {
            $error['db_user'] = '******';
        }
        if (!trim($options['resources']['db']['params']['dbname'])) {
            $error['db_name'] = 'Database name can not be blank';
        }
        if ((int) $options['settings']['keep_history'] <= 0) {
            $error['keep_history'] = 'Timeline display length have to be positive integer';
        }
        if (!($db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => $options['resources']['db']['params']['host'], 'username' => $options['resources']['db']['params']['username'], 'password' => $options['resources']['db']['params']['password'], 'dbname' => $options['resources']['db']['params']['dbname'])))) {
            $error[] = 'Incorrect database connection details';
        }
        if (count($error)) {
            /**
             * Redirect back
             */
            $defaultNamespace->error = $error;
            $defaultNamespace->options = $options;
            $this->_helper->redirector('index', 'index', 'install');
        } else {
            /**
             * Execute db queries
             */
            $schemaSql = '
CREATE TABLE IF NOT EXISTS ' . $options['resources']['db']['params']['prefix'] . 'project (
  project_id int(10) unsigned NOT NULL AUTO_INCREMENT,
  project_name varchar(255) NOT NULL,
  project_status TINYINT(1) UNSIGNED NOT NULL DEFAULT \'1\',
  PRIMARY KEY (project_id)
);

CREATE TABLE IF NOT EXISTS ' . $options['resources']['db']['params']['prefix'] . 'project_to_query (
  project_id int(10) unsigned NOT NULL,
  query_id int(10) unsigned NOT NULL,
  UNIQUE KEY project_id (project_id,query_id)
);

CREATE TABLE IF NOT EXISTS ' . $options['resources']['db']['params']['prefix'] . 'query (
  query_id int(10) unsigned NOT NULL AUTO_INCREMENT,
  query_q varchar(255) NOT NULL,
  query_lang char(2) NOT NULL,
  query_geocode varchar(255) NOT NULL,
  query_nearplace varchar(255) NOT NULL,
  query_distance int(10) NOT NULL,
  query_distanceunit varchar(30) NOT NULL,
  query_last_twitter varchar(255) NOT NULL,
  query_last_facebook varchar(255) NOT NULL,
  PRIMARY KEY (query_id)
);

CREATE TABLE IF NOT EXISTS ' . $options['resources']['db']['params']['prefix'] . 'search (
  search_id int(10) unsigned NOT NULL AUTO_INCREMENT,
  query_id int(10) unsigned NOT NULL,
  search_outer_id VARCHAR( 255 ) NOT NULL ,
  search_source VARCHAR( 255 ) NOT NULL ,
  search_published INT( 10 ) UNSIGNED NOT NULL ,
  search_title VARCHAR( 255 ) NOT NULL ,
  search_content TEXT NOT NULL ,
  search_author_name VARCHAR( 255 ) NOT NULL ,
  search_author_image VARCHAR( 255 ) NOT NULL ,
  PRIMARY KEY (search_id)
);

CREATE TABLE IF NOT EXISTS ' . $options['resources']['db']['params']['prefix'] . 'search_index (
  query_id int(10) NOT NULL,
  index_date int(10) NOT NULL,
  index_source varchar(255) NOT NULL,
  index_count int(5) NOT NULL,
  UNIQUE KEY query_id (query_id,index_date,index_source)
);

CREATE TABLE  IF NOT EXISTS ' . $options['resources']['db']['params']['prefix'] . 'search_influencers (
  query_id int(10) unsigned NOT NULL,
  search_author_name varchar(255) NOT NULL,
  search_author_uri varchar(255) NOT NULL,
  cnt int(5) unsigned NOT NULL,
  search_source varchar(255) NOT NULL,
  UNIQUE KEY query_id (query_id,search_author_name)
);';
            $db->getConnection()->exec($schemaSql);
            /**
             * Write .ini file
             */
            /** @var $bootstrap Bootstrap */
            unset($defaultNamespace->options);
            $bootstrap = $this->getInvokeArg('bootstrap');
            $options = new Zend_Config($options);
            $writer = new Zend_Config_Writer_Xml();
            $writer->write($bootstrap->getOption('local_config'), $options);
            $this->_helper->redirector('index', 'index', 'default');
        }
    }
Exemplo n.º 7
0
 /**
  */
 public function getZendDbPdoMysqlConnection()
 {
     $db_params = $this->getDbParams();
     $params = array();
     foreach (self::$_application_ini_map as $k => $v) {
         if (isset($db_params[$k])) {
             $params[$v] = $db_params[$k];
         }
     }
     #require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
     $db = new Zend_Db_Adapter_Pdo_Mysql($params);
     return $db->getConnection();
 }