当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Db::factory方法代码示例

本文整理汇总了PHP中Zend_Db::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db::factory方法的具体用法?PHP Zend_Db::factory怎么用?PHP Zend_Db::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Db的用法示例。


在下文中一共展示了Zend_Db::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructor.
  *
  * $config is an array of key/value pairs or an instance of Zend_Config
  * containing configuration options.  These options are common to most adapters:
  *
  * dbname         => (string) The name of the database to user
  * username       => (string) Connect to the database as this username.
  * password       => (string) Password associated with the username.
  * host           => (string) What host to connect to, defaults to localhost
  *
  * Some options are used on a case-by-case basis by adapters:
  *
  * port           => (string) The port of the database
  * persistent     => (boolean) Whether to use a persistent connection or not, defaults to false
  * protocol       => (string) The network protocol, defaults to TCPIP
  * caseFolding    => (int) style of case-alteration used for identifiers
  *
  * @param  array|Zend_Config $config An array or instance of Zend_Config having configuration data
  * @throws Zend_Db_Adapter_Exception
  */
 public function __construct($config)
 {
     /*
      * Verify that adapter parameters are in an array.
      */
     if (!is_array($config)) {
         /*
          * Convert Zend_Config argument to a plain array.
          */
         if ($config instanceof Zend_Config) {
             $config = $config->toArray();
         } else {
             /**
              * @see Zend_Db_Adapter_Exception
              */
             require_once 'Zend/Db/Adapter/Exception.php';
             throw new Zend_Db_Adapter_Exception('Adapter parameters must be in an array or a Zend_Config object');
         }
     }
     $this->_checkRequiredOptions($config);
     $this->_config = $config;
     foreach ($this->_config[self::CONNECTION_MASTERS] as $name => $config) {
         $this->_connections[self::CONNECTION_MASTERS][$name] = Zend_Db::factory(new Zend_Config($config));
     }
     foreach ($this->_config[self::CONNECTION_SLAVES] as $name => $config) {
         $this->_connections[self::CONNECTION_SLAVES][$name] = Zend_Db::factory(new Zend_Config($config));
     }
 }
开发者ID:BGCX261,项目名称:zrails-svn-to-git,代码行数:49,代码来源:Replication.php

示例2: _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);
 }
开发者ID:rtsantos,项目名称:mais,代码行数:33,代码来源:CrudTProvider.php

示例3: _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);
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:15,代码来源:DbInspector.php

示例4: 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;
 }
开发者ID:JudonH,项目名称:writer,代码行数:32,代码来源:Mysql.php

示例5: getResource

 public function getResource()
 {
     if (!$this->_resource) {
         $this->_resource = Zend_Db::factory($this->getVar('adapter', 'Pdo_Mysql'), $this->getVars());
     }
     return $this->_resource;
 }
开发者ID:arslbbt,项目名称:mangentovies,代码行数:7,代码来源:Db.php

示例6: 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);
         }
     }
 }
开发者ID:BGCX262,项目名称:zym-svn-to-git,代码行数:31,代码来源:Db.php

示例7: 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);
 }
开发者ID:albertobraschi,项目名称:zstarter,代码行数:7,代码来源:Kernel.php

示例8: _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;
 }
开发者ID:kaibaok,项目名称:xs,代码行数:7,代码来源:Bootstrap.php

示例9: 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);
 }
开发者ID:lynguyetvan88,项目名称:kemsakura,代码行数:28,代码来源:IndexController.php

示例10: _initDatabase

 protected function _initDatabase()
 {
     $config = $this->getOptions();
     $db = Zend_Db::factory($config['resources']['db']['adapter'], $config['resources']['db']['params']);
     Zend_Db_Table::setDefaultAdapter($db);
     Zend_Registry::set("db", $db);
 }
开发者ID:MonCoder189,项目名称:Work,代码行数:7,代码来源:Bootstrap.php

示例11: testAction

 public function testAction()
 {
     $time_start = microtime(true);
     $params = array('host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'dbname' => 'langithp');
     $db = Zend_Db::factory('PDO_MYSQL', $params);
     Zend_Db_Table_Abstract::setDefaultAdapter($db);
     require_once '/Users/n/Documents/Work/Zend/kutump/test/CatalogAttribute.php';
     $tbl = new CatalogAttribute();
     $rows = $tbl->fetchAll();
     $num = count($rows);
     echo "<b><center>Database Output</center></b><br><br>";
     $i = 0;
     for ($i = 0; $i < $num; $i++) {
         //$tmpGuid = mysql_result($result,$i,"guid");
         $row = $rows->current();
         $tmpGuid = $row->title;
         echo '<br>' . $tmpGuid;
         echo '<br>' . $i;
         $rows->next();
         //$i++;
     }
     $dbh = null;
     echo '<br>Total: ' . $i;
     $time_end = microtime(true);
     $time = $time_end - $time_start;
     echo '<br>WAKTU EKSEKUSI: ' . $time;
     //die('hiho');
 }
开发者ID:psykomo,项目名称:kutump,代码行数:28,代码来源:IndexController.php

示例12: __construct

 /**
  * 
  * @see Spizer_Logger_Interface::__construct()
  */
 public function __construct($config = array())
 {
     if (!extension_loaded('pdo_sqlite')) {
         require_once 'Spizer/Logger/Exception.php';
         throw new Spizer_Logger_Exception("The PDO_SQLITE extension is required in order to use the Sqlite logger");
     }
     if (!isset($config['dbfile'])) {
         require_once 'Spizer/Logger/Exception.php';
         throw new Spizer_Logger_Exception("The Sqlite logger requires a real DB output file to be set");
     }
     // Instantiate the adapter
     $this->_db = Zend_Db::factory('PDO_SQLITE', array('dbname' => $config['dbfile']));
     // Set up the database and tables
     if (!(isset($config['append']) && $config['append'])) {
         $this->_db->query("DROP TABLE IF EXISTS requests");
         $this->_db->query("DROP TABLE IF EXISTS request_headers");
         $this->_db->query("DROP TABLE IF EXISTS responses");
         $this->_db->query("DROP TABLE IF EXISTS response_headers");
         $this->_db->query("DROP TABLE IF EXISTS messages");
     }
     $this->_db->query("CREATE TABLE IF NOT EXISTS requests(\n        \t\t\t\t\tid INTEGER NOT NULL PRIMARY KEY, \n        \t\t\t\t\tmicrotime REAL NOT NULL, \n        \t\t\t\t\turl TEXT NOT NULL,\n        \t\t\t\t\treferrer TEXT, \n        \t\t\t\t\tmethod VARCHAR(10) NOT NULL)");
     $this->_db->query("CREATE TABLE IF NOT EXISTS request_headers(\n        \t\t\t\t\tid INTEGER NOT NULL PRIMARY KEY, \n        \t\t\t\t\trequest_id INTEGER NOT NULL, \n        \t\t\t\t\theader VARCHAR(50) NOT NULL, \n        \t\t\t\t\tvalue TEXT)");
     $this->_db->query("CREATE TABLE IF NOT EXISTS responses(\n        \t\t\t\t\tid INTEGER NOT NULL PRIMARY KEY, \n        \t\t\t\t\trequest_id INTEGER NOT NULL, \n        \t\t\t\t\tmicrotime REAL NOT NULL, \n        \t\t\t\t\tstatuscode INTEGER NOT NULL, \n        \t\t\t\t\tmessage VARCHAR(30) NOT NULL)");
     $this->_db->query("CREATE TABLE IF NOT EXISTS response_headers(\n        \t\t\t\t\tid INTEGER NOT NULL PRIMARY KEY, \n        \t\t\t\t\trequest_id INTEGER NOT NULL, \n        \t\t\t\t\theader VARCHAR(50) NOT NULL, \n        \t\t\t\t\tvalue TEXT)");
     $this->_db->query("CREATE TABLE IF NOT EXISTS messages(\n        \t\t\t\t\tid INTEGER NOT NULL PRIMARY KEY, \n        \t\t\t\t\trequest_id INTEGER NOT NULL, \n        \t\t\t\t\thandler VARCHAR(30) NOT NULL, \n        \t\t\t\t\tkey VARCHAR(30) NOT NULL, \n        \t\t\t\t\tvalue TEXT)");
 }
开发者ID:highestgoodlikewater,项目名称:spizer,代码行数:30,代码来源:Sqlite.php

示例13: __construct

 public function __construct($addr = "127.0.0.1", $port = 8080)
 {
     $this->port = $port;
     $this->addr = $addr;
     // Setup basic stuff
     error_reporting(E_ALL & ~E_NOTICE);
     $base = realpath(dirname(__FILE__) . '/../');
     $paths = array('.', realpath($base . '/library'), get_include_path());
     $this->base = $base;
     // Setup autoloading ...
     set_include_path(implode(PATH_SEPARATOR, $paths));
     require_once 'Zend/Loader/Autoloader.php';
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->registerNamespace('EvHttp_');
     $resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => realpath($base . '/application'), 'namespace' => '', 'resourceTypes' => array('model' => array('namespace' => 'Model', 'path' => 'models/'), 'api' => array('namespace' => 'Service', 'path' => 'apis/'))));
     // Load config
     $this->config = new Zend_Config_Ini($this->base . '/deploy/config.ini', 'default');
     Zend_Registry::set('config', $this->config);
     // Connect database
     $dbType = $this->config->database->type;
     $params = $this->config->database->toArray();
     $db = Zend_Db::factory($dbType, $params);
     Zend_Db_Table::setDefaultAdapter($db);
     Zend_Registry::set('db', $db);
     // Setup Xml-Rpc Server
     $this->xmlrpc_server = new Zend_XmlRpc_Server();
     $this->xmlrpc_server->setClass('Service_Poll', 'poll');
     Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
     // Setup Json-Rpc Server
     $this->jsonrpc_server = new Zend_Json_Server();
     $this->jsonrpc_server->setClass('Service_Poll', 'poll')->setAutoEmitResponse(false)->setTarget('/jsonrpc')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
 }
开发者ID:dreamsxin,项目名称:Kellner,代码行数:32,代码来源:main.php

示例14: __construct

 public function __construct($option = null)
 {
     parent::__construct($option);
     $this->setName('sum');
     $name = new Zend_Form_Element_Text('name');
     $name->setLabel('Сумын нэрийг оруулна уу ?')->setRequired(true)->addFilter(new Zend_Filter_StringTrim())->addValidator(new Zend_Validate_NotEmpty())->setAttrib('class', "form-control");
     $aimag = new Zend_Form_Element_Select("aimag");
     //create obj
     $aimag->setAttrib('class', "form-control")->setRequired()->setLabel("Та аймагаа сонгоно уу?");
     $params = array('host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'dbname' => 'dun');
     $db = Zend_Db::factory("mysqli", $params);
     $sql = $db->quoteInto('select * from aimag', null);
     $users = $db->query($sql)->fetchAll();
     $userArray = array();
     foreach ($users as $user) {
         /*use value as the key,while form submited,key was added into response obj*/
         $userArray[$user['name']] = $user['name'];
         //create the $list
     }
     $aimag->addMultiOptions($userArray);
     $add = new Zend_Form_Element_Submit('add');
     $add->setLabel('Нэмэх')->setAttrib('class', 'btn');
     $this->addElement($aimag);
     $this->addElement($name);
     $this->addElement($add);
     $this->setMethod('post');
 }
开发者ID:MonCoder189,项目名称:Work,代码行数:27,代码来源:Sum.php

示例15: __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;
 }
开发者ID:rjon76,项目名称:netspotapp,代码行数:29,代码来源:localString.php


注:本文中的Zend_Db::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。