示例#1
0
 /**
  * Faz o upload da imagem
  *
  * @return array
  */
 public function saveImage($array)
 {
     $db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'painelpadrao_imagem'));
     $form = array("nm_avatar" => $array["file"]["name"], "tp_avatar" => $array["file"]["type"], "sz_avatar" => $array["file"]["size"], "arquivo" => file_get_contents($array["file"]["tmp_name"]));
     $result = $db->insert("imagem", $form);
     //$sql = "SELECT * FROM imagem WHERE id_avatar = ".$id;
     return $result;
 }
 public function indexAction()
 {
     $db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'alphahyd'));
     $aTables = $db->listTables();
     $this->view->tables = $aTables;
     $sql = 'SHOW COLUMNS FROM alphahyd.tmp';
     $aRowTables = $db->describeTable('categories');
     $this->view->rowTable = $aRowTables;
     //var_dump($aRowTables);
 }
示例#3
0
 public function testFetchItem()
 {
     $data = [1 => 'test'];
     $statementMock = $this->getMock('Zend_Db_Statement_Pdo', ['fetch'], [], '', false);
     $statementMock->expects($this->once())->method('fetch')->will($this->returnValue($data));
     $this->adapterMock->expects($this->once())->method('query')->with($this->selectMock, $this->anything())->will($this->returnValue($statementMock));
     $objectMock = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['setData'], [], '', false);
     $objectMock->expects($this->once())->method('setData')->with($data);
     $this->entityFactoryMock->expects($this->once())->method('create')->with('Magento\\Review\\Model\\Review\\Summary')->will($this->returnValue($objectMock));
     $item = $this->collection->fetchItem();
     $this->assertEquals($objectMock, $item);
     $this->assertEquals('id', $item->getIdFieldName());
 }
示例#4
0
 public function testAdapterExceptionInvalidLoginCredentials()
 {
     $params = $this->_util->getParams();
     $params['password'] = 'xxxxxxxx';
     // 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));
     }
 }
示例#5
0
 /**
  * Connects to the database.
  *
  */
 protected function _connect()
 {
     parent::_connect();
     if (!$this->_initialized) {
         $this->_initialized = true;
         if ($this->_config['timezone']) {
             // Requires PHP 5.2+
             $dtz = new DateTimeZone($this->_config['timezone']);
             $offset = $dtz->getOffset(new DateTime('NOW')) / 60 / 60;
             if ($offset > 0) {
                 $offset = "+" . $offset;
             }
             /*
             echo "location: ".$dtz->getLocation()."<br />";
             echo "offset: ".$dtz->getOffset(new DateTime('NOW'))."<br />";
             echo "offset 2: ". $offset."<br />";
             echo "SET time_zone = '$offset:00'"."<br />";
             */
             $this->query("SET time_zone = '{$offset}:00';");
             //sprintf("SET time_zone = '%d:00'", $offset));
             /*
                             $timezone = new DateTimeZone($this->_config['timezone']);
                             $minutes = $timezone->getOffset(new DateTime('NOW')) / 60 / 60;
                             
                             
                             
                             //$offset = sprintf("SET time_zone = '%d:%2d'", $minutes / 60, $minutes % 60);
                             $offset = sprintf("SET time_zone = '%d:00'", $offset);
             *
             */
         }
     }
 }
示例#6
0
 function rollBack()
 {
     $this->_transaction_depth--;
     if ($this->shouldEmulateNesting()) {
         return;
     }
     return parent::rollBack();
 }
示例#7
0
 /**
  * get select for tags query
  *
  * @param string|array $_recordId
  * @param string $_applicationId
  * @param mixed $_cols
  * @return Zend_Db_Select
  */
 protected function _getSelect($_recordId, $_applicationId, $_cols = '*')
 {
     array_walk($_recordId, function (&$value, $index) {
         $value = (string) $value;
     });
     $select = $this->_db->select()->from(array('tagging' => SQL_TABLE_PREFIX . 'tagging'), $_cols)->join(array('tags' => SQL_TABLE_PREFIX . 'tags'), $this->_db->quoteIdentifier('tagging.tag_id') . ' = ' . $this->_db->quoteIdentifier('tags.id'))->where($this->_db->quoteIdentifier('application_id') . ' = ?', $_applicationId)->where($this->_db->quoteIdentifier('record_id') . ' IN (?) ', (array) $_recordId)->where($this->_db->quoteIdentifier('is_deleted') . ' = 0');
     return $select;
 }
示例#8
0
 public function rollback()
 {
     if ($this->_transactionLevel === 1) {
         return parent::rollback();
     }
     $this->_transactionLevel--;
     return $this;
 }
示例#9
0
 /**
  * Inserts a table row with specified data.
  *
  * @param mixed $table The table to insert data into.
  * @param array $bind Column-value pairs.
  * @return int The number of affected rows.
  */
 public function insert($table = null, array $bind = null)
 {
     if (is_null($table) && is_null($bind)) {
         return new Harmoni_Db_Insert($this);
     } else {
         return parent::insert($table, $bind);
     }
 }
示例#10
0
文件: Mysql.php 项目: cwcw/cms
 /**
  * Checks if the required options have been provided into the $config array
  *
  * @param array $config configuration options
  * @return void
  * @throws Streamwide_Db_Adapter_Exception
  */
 protected function _checkRequiredOptions(array $config)
 {
     if (!array_key_exists('host', $config)) {
         require_once 'Zend/Db/Adapter/Exception.php';
         throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'host' naming the hostname or ip of the database server");
     }
     parent::_checkRequiredOptions($config);
 }
示例#11
0
 protected function _connect()
 {
     // if we already have a PDO object, no need to re-connect.
     if ($this->_connection) {
         return;
     }
     parent::_connect();
     // set connection to utf8
     $this->query('SET NAMES utf8');
 }
示例#12
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');
     }
 }
示例#13
0
 /**
  * add single role rights 
  *
  * @param   int $_roleId
  * @param   int $_applicationId
  * @param   string $_right
  */
 public function addSingleRight($_roleId, $_applicationId, $_right)
 {
     // check if already in
     $select = $this->_roleRightsTable->select();
     $select->where($this->_db->quoteInto($this->_db->quoteIdentifier('role_id') . ' = ?', $_roleId))->where($this->_db->quoteInto($this->_db->quoteIdentifier('right') . ' = ?', $_right))->where($this->_db->quoteInto($this->_db->quoteIdentifier('application_id') . ' = ?', $_applicationId));
     if (!($row = $this->_roleRightsTable->fetchRow($select))) {
         $data = array('role_id' => $_roleId, 'application_id' => $_applicationId, 'right' => $_right);
         $this->_roleRightsTable->insert($data);
     }
 }
示例#14
0
 /**
  * Creates a PDO object and connects to the database.
  *
  * @return void
  * @throws Zend_Db_Adapter_Exception
  */
 protected function _connect()
 {
     if ($this->_connection) {
         return;
     }
     if (!empty($this->_config['timeout'])) {
         $this->_config['driver_options'][PDO::ATTR_TIMEOUT] = $this->_config['timeout'];
     }
     parent::_connect();
 }
示例#15
0
 /**
  * SUPER-FIXME!
  */
 public static function getAllAsociado($sitio = null, $pagina = null, $limit = 0, $orden = "id")
 {
     $registry = Zend_Registry::getInstance();
     $r = $registry->get('config');
     $db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => $r->db->config->host, 'username' => $r->db->config->username, 'password' => $r->db->config->password, 'dbname' => $r->db->config->dbname));
     $sql = ' select distinct(a.id),a.*, pa.* from archivos as a left join paginas_archivos as pa ON pa.id_archivo = a.id ';
     if ($sitio) {
         $where = "where ";
         $sql_add[] = "a.id_sitio = " . $sitio . " ";
     }
     if ($pagina) {
         $where = "where ";
         $sql_add[] = "pa.id_pagina = " . $pagina . " ";
     }
     $where = $where . implode(' AND ', $sql_add);
     echo $sql . $where;
     $result = $db->query($sql . $where);
     $archivos = $result->fetchAll();
     return $archivos;
 }
示例#16
0
 /**
  * Rollback DB transaction
  *
  * @return App_Zend_Db_Adapter_Mysqli
  */
 public function rollback()
 {
     if ($this->_txLevel === 1) {
         //        error_log("rollback tx for real");
         parent::rollback();
     } else {
         //        error_log("rollback tx " . $this->_txLevel-1);
     }
     $this->_txLevel--;
     return $this;
 }
 /**
  * Creates a PDO object and connects to the database.
  *
  * @return void
  * @throws Zend_Db_Adapter_Exception
  */
 protected function _connect()
 {
     if ($this->_connection) {
         return;
     }
     parent::_connect();
     if (isset($this->_config['options']['init_commands']) && is_array($this->_config['options']['init_commands'])) {
         foreach ($this->_config['options']['init_commands'] as $sqlInitCommand) {
             $this->_connection->exec($sqlInitCommand);
         }
     }
 }
示例#18
0
文件: Mysql.php 项目: nhp/shopware-4
 /**
  * Creates a PDO object and connects to the database.
  *
  * @return void
  * @throws Zend_Db_Adapter_Exception
  */
 protected function _connect()
 {
     // if we already have a PDO object, no need to re-connect.
     if ($this->_connection) {
         return;
     }
     try {
         parent::_connect();
     } catch (Exception $e) {
         $message = $e->getMessage();
         $message = str_replace(array($this->_config['username'], $this->_config['password']), '******', $message);
         throw new Zend_Db_Adapter_Exception($message, $e->getCode(), $e->getPrevious());
     }
     // finally, we delete the authorization data
     unset($this->_config['username'], $this->_config['password']);
 }
 /**
  * merge duplicate shared tags
  * 
  * @param string $model record model for which tags should be merged
  * @param boolean $deleteObsoleteTags
  * @param boolean $ignoreAcl
  * 
  * @see 0007354: function for merging duplicate tags
  */
 public function mergeDuplicateSharedTags($model, $deleteObsoleteTags = TRUE, $ignoreAcl = FALSE)
 {
     $select = $this->_db->select()->from(array('tags' => SQL_TABLE_PREFIX . 'tags'), 'name')->where($this->_db->quoteIdentifier('type') . ' = ?', Tinebase_Model_Tag::TYPE_SHARED)->where($this->_db->quoteIdentifier('is_deleted') . ' = 0')->group('name')->having('COUNT(' . $this->_db->quoteIdentifier('name') . ') > 1');
     $queryResult = $this->_db->fetchAll($select);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($queryResult) . ' duplicate tag names.');
     }
     $controller = Tinebase_Core::getApplicationInstance($model);
     if ($ignoreAcl) {
         $containerChecks = $controller->doContainerACLChecks(FALSE);
     }
     $recordFilterModel = $model . 'Filter';
     foreach ($queryResult as $duplicateTag) {
         $filter = new Tinebase_Model_TagFilter(array('name' => $duplicateTag['name'], 'type' => Tinebase_Model_Tag::TYPE_SHARED));
         $paging = new Tinebase_Model_Pagination(array('sort' => 'creation_time'));
         $tagsWithSameName = $this->searchTags($filter, $paging);
         $targetTag = $tagsWithSameName->getFirstRecord();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Merging tag ' . $duplicateTag['name'] . '. Found ' . count($tagsWithSameName) . ' tags with this name.');
         }
         foreach ($tagsWithSameName as $tag) {
             if ($tag->getId() === $targetTag->getId()) {
                 // skip target (oldest) tag
                 continue;
             }
             $recordFilter = new $recordFilterModel(array(array('field' => 'tag', 'operator' => 'in', 'value' => array($tag->getId()))));
             $recordIdsWithTagToMerge = $controller->search($recordFilter, NULL, FALSE, TRUE);
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($recordIdsWithTagToMerge) . ' ' . $model . '(s) with tags to be merged.');
             }
             if (!empty($recordIdsWithTagToMerge)) {
                 $recordFilter = new $recordFilterModel(array(array('field' => 'id', 'operator' => 'in', 'value' => $recordIdsWithTagToMerge)));
                 $this->attachTagToMultipleRecords($recordFilter, $targetTag);
                 $this->detachTagsFromMultipleRecords($recordFilter, $tag->getId());
             }
             // check occurrence of the merged tag and remove it if obsolete
             $tag = $this->get($tag);
             if ($deleteObsoleteTags && $tag->occurrence == 0) {
                 $this->deleteTags($tag->getId(), $ignoreAcl);
             }
         }
     }
     if ($ignoreAcl) {
         /** @noinspection PhpUndefinedVariableInspection */
         $controller->doContainerACLChecks($containerChecks);
     }
 }
示例#20
0
 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'.
  *
  * @param string|Zend_Db_Select $sql  The SQL statement with placeholders.
  * @param mixed                 $bind An array of data or data itself to bind to the placeholders.
  *
  * @return Zend_Db_Statement_Pdo
  * @throws Zend_Db_Adapter_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = [])
 {
     $this->_debugTimer();
     $result = null;
     try {
         $this->_checkDdlTransaction($sql);
         $this->_prepareQuery($sql, $bind);
         $maxTries = 1 + (isset($this->_config['retries']) ? min(max(intval($this->_config['retries']), 0), 5) : 5);
         $retryPower = isset($this->_config['retry_power']) ? min(max(intval($this->_config['retry_power']), 1), 5) : 2;
         $try = 0;
         while ($try < $maxTries) {
             try {
                 $result = Zend_Db_Adapter_Pdo_Mysql::query($sql, $bind);
                 $try = $maxTries;
             } catch (Exception $e) {
                 $try++;
                 Mage::log("Max retry:{$maxTries} retry power:{$retryPower}", Zend_Log::DEBUG);
                 if ($try < $maxTries) {
                     $message = null;
                     if ($e instanceof PDOException) {
                         $message = $e->getMessage();
                     } elseif ($e->getPrevious() instanceof PDOException) {
                         $message = $e->getPrevious()->getMessage();
                     } else {
                         Mage::log("Exception is instance of " . get_class($e), Zend_Log::DEBUG);
                         Mage::log("Previous Exception is instance of " . get_class($e->getPrevious()), Zend_Log::DEBUG);
                     }
                     if ($message && in_array($message, $this->retryOnMessages)) {
                         $sleepSeconds = pow($try, $retryPower);
                         Mage::log("Retrying query [retry:{$try} delay:{$sleepSeconds}]: {$message}", Zend_Log::DEBUG);
                         if ($try === 1) {
                             Mage::logException($e);
                         }
                         sleep($sleepSeconds);
                         continue;
                     }
                 }
                 throw $e;
             }
         }
     } catch (Exception $e) {
         $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
         $this->_debugException($e);
     }
     $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
     return $result;
 }
示例#21
0
文件: Mysql.php 项目: kandy/system
 /**
  * Rollback transaction
  * @return bool
  */
 protected function _rollBack()
 {
     if ($this->_nestedTransactionsCounter <= 0) {
         throw new Zend_Db_Adapter_Exception('Nested transactions error');
     }
     if (!$this->_isInRollback) {
         $result = parent::_rollBack();
         $this->_isInRollback = true;
     } else {
         $result = true;
     }
     $this->_nestedTransactionsCounter--;
     if ($this->_nestedTransactionsCounter == 0) {
         $this->_isInRollback = false;
     }
     return $result;
 }
示例#22
0
 /**
  * get registration by hash
  *
  * @param string $_hash the hash (md5 coded username) from the registration mail
  * @return Tinebase_Model_Registration the registration object
  *
  */
 public function getRegistrationByHash($_hash)
 {
     $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'registrations')->where($this->_db->quoteIdentifier('login_hash') . ' = ?', $_hash);
     $stmt = $select->query();
     $row = $stmt->fetch(Zend_Db::FETCH_ASSOC);
     if ($row === false) {
         throw new Tinebase_Exception_Record_NotDefined('registration entry not found error');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . "Tinebase_Model_Registration::row values: \n" . print_r($row, true));
     }
     try {
         $registration = new Tinebase_Model_Registration();
         $registration->setFromArray($row);
     } catch (Exception $e) {
         $validationErrors = $registration->getValidationErrors();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . $e->getMessage() . "\n" . "Tinebase_Model_Registration::validation_errors: \n" . print_r($validationErrors, true));
         }
         throw $e;
     }
     return $registration;
 }
示例#23
0
 protected function _connect()
 {
     if ($this->_connection) {
         return;
     }
     if (!extension_loaded('pdo_mysql')) {
         throw new Zend_Db_Adapter_Exception('pdo_mysql extension is not installed');
     }
     if (strpos($this->_config['host'], '/') !== false) {
         $this->_config['unix_socket'] = $this->_config['host'];
         $this->_config['host'] = null;
     } elseif (strpos($this->_config['host'], ':') !== false) {
         list($this->_config['host'], $this->_config['port']) = explode(':', $this->_config['host']);
     }
     parent::_connect();
     /** @link http://bugs.mysql.com/bug.php?id=18551 */
     $this->_connection->query("SET SQL_MODE=''");
     if (!$this->_connectionFlagsSet) {
         $this->_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
         #$this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
         $this->_connectionFlagsSet = true;
     }
 }
示例#24
0
 public function _dsn()
 {
     return parent::_dsn();
 }
示例#25
0
 /**
  * Returns the column descriptions for a table.
  *
  * The return value is an associative array keyed by the column name,
  * as returned by the RDBMS.
  *
  * The value of each array element is an associative array
  * with the following keys:
  *
  * SCHEMA_NAME      => string; name of database or schema
  * TABLE_NAME       => string;
  * COLUMN_NAME      => string; column name
  * COLUMN_POSITION  => number; ordinal position of column in table
  * DATA_TYPE        => string; SQL datatype name of column
  * DEFAULT          => string; default expression of column, null if none
  * NULLABLE         => boolean; true if column can have nulls
  * LENGTH           => number; length of CHAR/VARCHAR
  * SCALE            => number; scale of NUMERIC/DECIMAL
  * PRECISION        => number; precision of NUMERIC/DECIMAL
  * UNSIGNED         => boolean; unsigned property of an integer type
  * PRIMARY          => boolean; true if column is part of the primary key
  * PRIMARY_POSITION => integer; position of column in primary key
  * IDENTITY         => integer; true if column is auto-generated with unique values
  *
  * @param string $tableName
  * @param string $schemaName OPTIONAL
  * @return array
  */
 public function describeTable($tableName, $schemaName = null)
 {
     $cacheKey = $this->_getTableName($tableName, $schemaName);
     $ddl = $this->loadDdlCache($cacheKey, self::DDL_DESCRIBE);
     if ($ddl === false) {
         $ddl = parent::describeTable($tableName, $schemaName);
         /**
          * Remove bug in some MySQL versions, when int-column without default value is described as:
          * having default empty string value
          */
         $affected = array('tinyint', 'smallint', 'mediumint', 'int', 'bigint');
         foreach ($ddl as $key => $columnData) {
             if ($columnData['DEFAULT'] === '' && array_search($columnData['DATA_TYPE'], $affected) !== FALSE) {
                 $ddl[$key]['DEFAULT'] = null;
             }
         }
         $this->saveDdlCache($cacheKey, self::DDL_DESCRIBE, $ddl);
     }
     return $ddl;
 }
示例#26
0
 // setup the database for the phpunit_pimcore
 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 .= ";";
<?php

set_include_path(realpath(dirname(__FILE__) . '/../vendor/zendframework/zendframework1/library'));
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
$db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => 'localhost', 'charset' => 'utf8', 'dbname' => 'hello_world', 'username' => 'benchmarkdbuser', 'password' => 'benchmarkdbpass'));
$db->exec('DROP TABLE IF EXISTS `World`;');
$db->exec('CREATE TABLE `World` (
  `id` int(11) NOT NULL,
  `randomNumber` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
for ($i = 1; $i <= 10000; $i++) {
    $db->insert('World', array('id' => $i, 'randomNumber' => $i));
}
示例#28
0
文件: Action.php 项目: basdog22/Qool
 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;
 }
示例#29
0
 /**
  * Returns the column descriptions for a table.
  *
  * The return value is an associative array keyed by the column name,
  * as returned by the RDBMS.
  *
  * The value of each array element is an associative array
  * with the following keys:
  *
  * SCHEMA_NAME      => string; name of database or schema
  * TABLE_NAME       => string;
  * COLUMN_NAME      => string; column name
  * COLUMN_POSITION  => number; ordinal position of column in table
  * DATA_TYPE        => string; SQL datatype name of column
  * DEFAULT          => string; default expression of column, null if none
  * NULLABLE         => boolean; true if column can have nulls
  * LENGTH           => number; length of CHAR/VARCHAR
  * SCALE            => number; scale of NUMERIC/DECIMAL
  * PRECISION        => number; precision of NUMERIC/DECIMAL
  * UNSIGNED         => boolean; unsigned property of an integer type
  * PRIMARY          => boolean; true if column is part of the primary key
  * PRIMARY_POSITION => integer; position of column in primary key
  * IDENTITY         => integer; true if column is auto-generated with unique values
  *
  * @param string $tableName
  * @param string $schemaName OPTIONAL
  * @return array
  */
 public function describeTable($tableName, $schemaName = null)
 {
     $cacheKey = $this->_getTableName($tableName, $schemaName);
     $ddl = $this->loadDdlCache($cacheKey, self::DDL_DESCRIBE);
     if ($ddl === false) {
         $ddl = parent::describeTable($tableName, $schemaName);
         $this->saveDdlCache($cacheKey, self::DDL_DESCRIBE, $ddl);
     }
     return $ddl;
 }
示例#30
0
 /**
  * Operational test for the MySQL database instance:
  * @param  PDO|Zend_Db_Adapter_Pdo_Mysql  $db  Zend Db adapter instance
  * @return boolean   sanity check result
  */
 private static function testDb($db)
 {
     $expected = array('posts' => null, 'users' => null, 'topics' => null, 'attachments' => null);
     foreach ($db->query('show tables') as $row) {
         unset($expected[array_pop($row)]);
     }
     if (count($expected)) {
         ZFDemo_Log::log(_('database missing tables: ') . implode(' ', $expected));
         return false;
     }
     return true;
 }