本文整理汇总了PHP中Zend_Db类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db类的具体用法?PHP Zend_Db怎么用?PHP Zend_Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initZendDb
public function _initZendDb(Yaf_Dispatcher $dispatcher)
{
$arrConfig = Yaf_Application::app()->getConfig();
$zendDb = new Zend_Db();
$params = array('host' => $arrConfig->mysql->read->host, 'username' => $arrConfig->mysql->read->username, 'password' => $arrConfig->mysql->read->password, 'dbname' => $arrConfig->mysql->read->dbname, 'port' => $arrConfig->mysql->read->port);
$db = $zendDb->factory('PDO_MYSQL', $params);
Yaf_Registry::set('db', $db);
}
示例2: _initDb
protected function _initDb()
{
$resources = $this->getOption('resources');
$dbConfig = $resources['db'];
$db = \Zend_Db::factory($dbConfig['adapter'], array('host' => $dbConfig['params']['host'], 'username' => $dbConfig['params']['username'], 'password' => $dbConfig['params']['password'], 'dbname' => $dbConfig['params']['dbname'], 'adapterNamespace' => $dbConfig['params']['adapterNamespace']));
\Zend_Db_Table::setDefaultAdapter($db);
}
示例3: setup
/**
* Setup db
*
*/
public function setup(Zend_Config $config)
{
// Determine if config is for a single-db or a multi-db site
$dbConfigs = isset($config->dbname) ? array($config) : $config->get('connection');
foreach ($dbConfigs as $dbConfig) {
// Merge default config
$dbConfig = $this->_mergeConfig($config->get('default_config'), $dbConfig);
// TODO: Cleanup config
// Sigh, bad code in Zend_Db_Adapter_Abstract... we cannot have an empty string for profile class
// Create db adapter
$db = Zend_Db::factory($dbConfig->get('adapter'), $dbConfig->toArray());
// Setup profiler
$this->_setupProfiler($dbConfig->get('profiler'), $db);
// Setup tables
$this->_setupTables($dbConfig, $db);
// Make sure db keys don't already exist, else add numbers to them such as db-2, db-3
$dbKey = $this->_makeDbKey($dbConfig->get('registry')->get('key'));
// Store db obj
$this->setAdapter($db, $dbKey);
// Determine if we should save the db adapter in the registry
$dbRegistryDisabled = isset($dbConfig->get('registry')->disabled) && $dbConfig->get('registry')->get('disabled') === '' || $dbConfig->get('registry')->get('disabled') == true;
if (!$dbRegistryDisabled) {
// Save in registry
Zend_Registry::set($dbKey, $db);
}
}
}
示例4: _database
protected function _database()
{
$this->_db = Zend_Db::factory('Pdo_Mysql', array('host' => 'localhost', 'username' => 'test_bruno', 'password' => 'test_bruno', 'dbname' => 'test_bruno'));
$this->_db->exec("SET NAMES 'utf8'");
Zend_Db_Table::setDefaultAdapter($this->_db);
return $this;
}
示例5: __construct
public function __construct($siteId)
{
$this->siteId = $siteId;
$this->dbAdapter = Zend_Registry::get('dbAdapter');
$dbAdapter = Zend_Registry::get('dbAdapter');
$config = Zend_Registry::get('config');
$params = $config->db->config->toArray();
// $params['dbname'] = 'venginse_all';
$params['dbname'] = $config->db->config->dballname;
$this->alldbAdapter = Zend_Db::factory($config->db->adapter, $params);
$select = $dbAdapter->select();
$select->from('sites', array('s_dbname', 's_path'));
$select->where('s_id = ?', $siteId);
$config = $dbAdapter->fetchRow($select->__toString());
$this->siteDbName = $config['s_dbname'];
$this->sitePath = $config['s_path'];
include_once $this->sitePath . 'application/includes.inc.php';
IniParser::getInstance()->setIni($this->sitePath . 'application/config.ini', TRUE);
$config = Zend_Registry::get('config');
$params = $config->db->config->toArray();
$params['dbname'] = $this->siteDbName;
$this->siteDbAdapter = Zend_Db::factory($config->db->adapter, $params);
Zend_Registry::set('siteDbAdapter', $this->siteDbAdapter);
$this->siteDbAdapter->query('SET NAMES utf8');
$this->alldbAdapter->query('SET NAMES utf8');
$this->loadLangs();
$this->recCount = $this->countStrings();
$this->recPerPage = 20;
}
示例6: _connect
/**
*
* @param Zend_Tool_Project_Profile $profile
* @param type $adapter
* @throws Zend_Tool_Project_Exception
*/
private function _connect(Zend_Tool_Project_Profile $profile, $adapter, $env = 'development')
{
$applicationConfigResource = $profile->search('ApplicationConfigFile');
if ($env == null || $env == '') {
$env = 'development';
}
if (!$applicationConfigResource) {
throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
}
//$conn = 'testing';
//$conn = 'development';
$zf = $applicationConfigResource->getAsZendConfig($env);
$this->_print('Conectado em ' . $env);
#$zf = $applicationConfigResource->getAsZendConfig('testing');
$_configDb = $zf->resources->multidb->{$adapter};
if (!$_configDb) {
throw new Zend_Tool_Project_Exception('Adapter not found in config application "resources.multidb.' . $adapter . '" .');
}
$configDb = array();
$configDb['host'] = $_configDb->host;
$configDb['username'] = $_configDb->username;
$configDb['password'] = $_configDb->password;
$configDb['dbname'] = $_configDb->dbname;
$configDb['adapterNamespace'] = $_configDb->adapterNamespace;
$configDb['options']['caseFolding'] = 1;
$this->_dbAdapter = Zend_Db::factory($_configDb->adapter, $configDb);
}
示例7: _connect
/**
* Connect to the database
*
* @param string $dbType Database adapter type for Zend_Db
* @param array|object $dbDescription Adapter-specific connection settings
* @return Zend_Db_Adapter_Abstract
* @see Zend_Db::factory()
*/
protected function _connect($dbType, $dbDescription)
{
if (is_object($dbDescription)) {
$dbDescription = get_object_vars($dbDescription);
}
return Zend_Db::factory($dbType, $dbDescription);
}
示例8: getDb
/**
* 返回数据库连接
* 从http服务器读取配置,格式: SetEnv DB_$dbid PDO_MYSQL/$ip/$port/$db/$user/$passwd/$charset
* @param mixed $dbid 数据库连接代号
* @return object Zend_Db对象
*/
public static function getDb($dbid)
{
if (Esun_ConfigCenter::isExsitConfigcenter()) {
$confinfo = Esun_ConfigCenter::getconfig("DB_{$dbid}");
} else {
$confinfo = $_SERVER['DB_' . $dbid];
}
$conf = explode('/', $confinfo);
$params = array('host' => $conf[1], 'port' => (int) $conf[2], 'dbname' => $conf[3], 'username' => $conf[4], 'password' => $conf[5], 'charset' => $conf[6], 'options' => array(Zend_Db::AUTO_QUOTE_IDENTIFIERS => false));
if (preg_match('/PDO_MSSQL/i', $conf[0])) {
$params['pdoType'] = 'dblib';
$params['options'][Zend_Db::CASE_FOLDING] = Zend_Db::CASE_UPPER;
} elseif (preg_match('/ORACLE/i', $conf[0])) {
if ($conf[1] && $conf[2]) {
$params['dbname'] = "//{$conf[1]}:{$conf[2]}/{$conf[3]}";
}
}
$db = Zend_Db::factory($conf[0], $params);
if (preg_match('/PDO_MYSQL/i', $conf[0])) {
$db->query("SET NAMES " . $conf[6]);
$db->query("set session transaction isolation level read committed");
} elseif (preg_match('/ORACLE|PDO_OCI/i', $conf[0])) {
$db->query("alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'");
}
return $db;
}
示例9: getResource
public function getResource()
{
if (!$this->_resource) {
$this->_resource = Zend_Db::factory($this->getVar('adapter', 'Pdo_Mysql'), $this->getVars());
}
return $this->_resource;
}
示例10: run
public function run()
{
// Lade Konfig
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
Zend_Registry::set('config', $config);
// Erstelle DB Adapter
$db = Zend_Db::factory($config->db);
Zend_Registry::set('db', $db);
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('db'));
if (APPLICATION_ENV !== 'production') {
$profiler = new Zend_Db_Profiler_Firebug('All Database Queries:');
$profiler->setEnabled(true);
$db->setProfiler($profiler);
}
$resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => APPLICATION_PATH, 'namespace' => ''));
$resourceLoader->addResourceType('plugins', 'plugins', 'Plugins');
if (PHP_SAPI != 'cli') {
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Plugins_Stats());
if (APPLICATION_ENV == 'production') {
$front->registerPlugin(new Plugins_Cache());
}
}
Zend_View_Helper_PaginationControl::setDefaultViewPartial('_partials/controls.phtml');
parent::run();
}
示例11: setDbAdapter
public static function setDbAdapter()
{
$cnf = Zend_Registry::get('cnf');
$db = Zend_Db::factory($cnf->db);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
}
示例12: _initDb
protected function _initDb()
{
$config = Zend_Registry::get('config');
$options = $config->mtb->db->params;
$db = Zend_Db::factory('PDO_MYSQL', $options);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
}
示例13: indexAction
public function indexAction()
{
// $db= Zend_Db::factory('pdo_mysql',array('dbname'=>'zendfw','host'=>'localhost','username'=>'root','password'=>''));
$filename = APPLICATION_PATH . '/configs/config.ini';
$config = new Zend_Config_Ini($filename);
$config = $config->toArray();
$configdb = $config['db'];
$adapter = $configdb['adapter'];
$params = $configdb[$adapter]['params'];
$db = Zend_Db::factory($adapter, $params);
var_dump($db);
// $userModel= new Default_Model_User();
// $userModel->addUser(array('name'=>'abc',
// 'password'=>'123456',
// 'fullname'=>'this is fullname'));
// $array_pdo= array(
// 'id'=>'10',
// 'name'=>'abc',
// 'password'=>'123456',
// 'fullname'=>'this is fullname',
// );
// $userModel->addUser($array_pdo);
// // $userModel->select();
//
// $test= new My_Db_Mysql();
// $test->test();
$this->_helper->viewRenderer->setNoRender(true);
}
示例14: setup
/**
* Creates and populates the DataSource
*
* @access public
* @return void
**/
public function setup()
{
$select = $this->getSelect();
if ($this->paginate) {
$sql = $this->getSelectCountSql();
$this->totalRows = (int) $this->_db->fetchOne($sql);
list($start, $total) = $this->limit;
$select->reset(Zend_Db_Select::LIMIT_COUNT);
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
$select->limit($total, $start);
} else {
$this->totalRows = 0;
}
$select->reset(Zend_Db_Select::ORDER);
if (count($this->order) > 0) {
$select->order($this->order);
}
// Fetch Select Columns
$rawColumns = $select->getPart(Zend_Db_Select::COLUMNS);
$columns = array();
// Get columns and Force casting as strings
foreach ($rawColumns as $col) {
$columns[] = (string) $col[1];
}
$this->cols = $columns;
$this->totalColumns = count($columns);
// Fetch
$stmt = $this->_db->query($select);
$rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
$total = count($rows);
$this->totalRowset = $total;
$this->rows = $rows;
}
示例15: _initDB
protected function _initDB()
{
$db = Zend_Db::factory('Pdo_Mysql', array('host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'xoso', 'charset' => 'utf8'));
$db->setFetchMode(Zend_Db::FETCH_BOTH);
Zend_Db_Table::setDefaultAdapter($db);
return $db;
}