public function testDbAdapterExceptionInvalidLoginCredentials() { $params = $this->_util->getParams(); $params['password'] = '******'; // invalid password try { $db = new Zend_Db_Adapter_Mysqli($params); $db->getConnection(); // force a connection $this->fail('Expected to catch Zend_Db_Adapter_Mysqli_Exception'); } catch (Exception $e) { $this->assertThat($e, $this->isInstanceOf('Zend_Db_Adapter_Mysqli_Exception'), 'Expected to catch Zend_Db_Adapter_Mysqli_Exception, got ' . get_class($e)); } }
/** * @param array $config */ public function __construct(array $config) { if (isset($config['bin_dir'])) { $this->_bin_dir = $config['bin_dir']; } parent::__construct($config); }
protected function _connect() { if ($this->_connection) { return; } try { parent::_connect(); } catch (Zend_Db_Adapter_Mysqli_Exception $e) { if (!is_null($this->_connectionErrorHandler)) { $f = $this->_connectionErrorHandler; $f($e); } throw $e; } }
/** * Change Db table engine * * @param string $table * - table name without prefix * @param string $engine * - new engine name * @param boolean $returnQuery * - optional, return update query * @return boolean | string * @throws Exception */ public function changeTableEngine($engine, $returnQuery = false) { if ($this->_objectConfig->isLocked() || $this->_objectConfig->isReadOnly()) { $this->_errors[] = 'Can not build locked object ' . $this->_objectConfig->getName(); return false; } $sql = 'ALTER TABLE `' . $this->_model->table() . '` ENGINE = ' . $engine; if ($returnQuery) { return $sql; } try { $this->_db->query($sql); $this->_logSql($sql); return true; } catch (Exception $e) { $this->_errors[] = $e->getMessage() . ' <br>SQL: ' . $sql; return false; } }
/** * データベーストランザクションを開始する. * @param Zend_Db_Adapter_Mysqli $db */ protected function _begin($db) { $this->_log->debug("_begin called(already):" . count($this->_dbs)); $db->beginTransaction(); $this->_dbs[] = $db; }
/** * Executa o comando SQL dentro do Banco de Dados * * @param string $sql * @param array $bind * @return bool */ public function query($sql, $bind = array()) { $cmd = strtolower(substr($sql, 0, 6)); ZendT_Config::$type = $this->_config['options']['charset']; $orderParam = array(); foreach ($bind as $name => $value) { if ($value instanceof ZendT_Type_Date) { $value = $value->getIso(); $value = str_replace('T', ' ', $value); } else { if ($value instanceof ZendT_Type_Number && in_array($cmd, array('insert', 'update'))) { $value = $value->getValueToDb(); if (!$value) { $value = null; } } else { if ($value instanceof ZendT_Type) { $value = $value->getValueToDb(); } } } $bind[$name] = $value; if (!is_numeric($name)) { $orderParam[] = $name; } } if (count($orderParam) > 0) { sort($orderParam); $count = count($orderParam) - 1; for ($i = $count; $i >= 0; $i--) { $name = $orderParam[$i]; $value = $bind[$name]; if (substr($name, 0, 1) != ':') { $sql = str_replace(':' . $name, $this->quote($value), $sql); } else { $sql = str_replace($name, $this->quote($value), $sql); } unset($bind[$name]); } } /* if (count($bind) > 0) { foreach ($bind as $name => $value) { if (!is_numeric($name)) { if (substr($name, 0, 1) != ':') { $sql = str_replace(':' . $name, $this->quote($value), $sql); } else { $sql = str_replace($name, $this->quote($value), $sql); } unset($bind[$name]); } } } */ return parent::query($sql, $bind); }
/** * Overload the query method of Zend Db * So we can debug the sql message * @see Hush_Debug * @param string $sql * @param array $bind * @return Zend_Db_Statement_Interface */ public function query($sql, $bind = array()) { if ($this->_debug) { require_once 'Hush/Debug.php'; $debug = Hush_Debug::getInstance(); $debug->setWriter(new Hush_Debug_Writer_Html()); // default can be override if (!$debug instanceof Hush_Debug) { require_once 'Zend/Db/Adapter/Exception.php'; throw new Zend_Db_Adapter_Exception("Can not initialize 'Hush_Debug' instance"); } if ($sql instanceof Zend_Db_Select) { $sql = $sql->__toString(); } if (sizeof($bind) > 0) { $label = 'Prepared Sql >>>'; } else { $label = 'Query Sql >>>'; } $debug->debug($sql, '<font style="color:red">' . $label . '</font>'); } return parent::query($sql, $bind); }
public function __construct($config) { parent::__construct($config); }
/** * Constructor * * @param array|Zend_Config $config database configuration */ public function __construct($config) { // Enable LOAD DATA INFILE $config['driver_options'][MYSQLI_OPT_LOCAL_INFILE] = true; parent::__construct($config); }
} /****************************************************************************** * Constants *****************************************************************************/ define('ROOT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR); define('ROOT_URL', get_base_url()); ini_set("include_path", ROOT_PATH . 'libs' . DIRECTORY_SEPARATOR); $loader = (require_once ROOT_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); use Symfony\Component\ClassLoader\UniversalClassLoader; $universalLoader = new UniversalClassLoader(); $universalLoader->useIncludePath(true); $universalLoader->register(); require_once 'Zend/Db/Adapter/Mysqli.php'; /****************************************************************************** * Loading of the options (default & user) *****************************************************************************/ if (!file_exists(ROOT_PATH . "options.php")) { die("The file options.php should exists, please read the instructions inside of 'options.php-example'."); } require_once ROOT_PATH . "options_default.php"; require_once ROOT_PATH . "options.php"; /****************************************************************************** * Initialize all the global variables *****************************************************************************/ require_once ROOT_PATH . '/services.php'; $g_database = new Zend_Db_Adapter_Mysqli($g_options['mysql']); $g_database->setFetchMode(Zend_Db::FETCH_OBJ); $g_database->query("SET NAMES utf8"); if (!defined('KNB_NO_DATABASE_ACCESS')) { $g_user = $serviceContainer->get('connectedUser'); }
private function getLinkFromConnectionInfo($connInfo) { $auth = Zotero_DBConnectAuth('shard'); $config = array('host' => $connInfo['address'], 'port' => $connInfo['port'], 'username' => $auth['user'], 'password' => $auth['pass'], 'dbname' => $connInfo['db'], 'charset' => !empty($auth['charset']) ? $auth['charset'] : 'utf8', 'driver_options' => array("MYSQLI_OPT_CONNECT_TIMEOUT" => 5)); // TEMP: For now, use separate host if (get_called_class() == 'Zotero_FullText_DB') { $auth = Zotero_DBConnectAuth('fulltext'); $config['host'] = $auth['host']; $config['port'] = $auth['port']; } else { if (get_called_class() == 'Zotero_Admin_DB') { $auth = Zotero_DBConnectAuth($this->db); $config['username'] = $auth['user']; $config['password'] = $auth['pass']; } } $link = new Zend_Db_Adapter_Mysqli($config); // If profile was previously enabled, enable it for this link if ($this->profilerEnabled) { $link->getProfiler()->setEnabled(true); } return $link; }
/** */ public function getZendDbMysqlConnection() { $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/Mysqli.php'; $db = new Zend_Db_Adapter_Mysqli($params); return $db->getConnection(); }
/** * @param \Zend_Config_Xml $config * @throws \Zend_Db_Adapter_Exception */ public function __construct(\Zend_Config_Xml $config) { parent::__construct($config->db->params); $this->dbprefix = $config->db->params->table_prefix; }