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


PHP Database_Connection::instance方法代码示例

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


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

示例1: database

 /**
  * Load database configuration.
  *
  * @return  bool  returns true on success or sets error messages and returns false.
  */
 public static function database()
 {
     // load database config
     if (!\Config::load('db', true)) {
         Error::set(CRUDE_ERROR, 'Fuel database configuration file not found.');
         Error::set(CRUDE_SOLUTION, 'Check that the database configuration file <code>APPPATH' . DS . 'config' . DS . 'db.php</code> exists and is properly formatted. See ' . \Html::anchor('http://fuelphp.com/docs/classes/database/introduction.html', 'Fuel documentation', array('target' => '_blank')));
         return false;
     }
     // check database connection. Thanks, Jelmer.
     try {
         @\Database_Connection::instance()->connect();
     } catch (\Database_Exception $e) {
         // can't seem to properly catch database authentication errors
         // hack to trap authentication error. there are probably other errors involved here.
         $msg = $e->getMessage();
         if (empty($msg)) {
             $msg = 'Access to database <code>' . \Config::get('db.' . \Config::get('environment') . '.connection.database') . '</code> was denied.';
         }
         $msg = str_replace('\'', '"', $msg);
         Error::set(CRUDE_FUEL_ERR, $msg);
         Error::set(CRUDE_SOLUTION, 'Check that the database configuration file <code>APPPATH' . DS . 'config' . DS . 'db.php</code> contains the correct information to connect to your database. See ' . \Html::anchor('http://fuelphp.com/docs/classes/database/introduction.html', 'Fuel documentation', array('target' => '_blank')));
         return false;
     }
     // check that tables exist in the database
     $tables = \DB::list_tables();
     if (empty($tables)) {
         Error::set(CRUDE_ERROR, 'No tables found in database <code>' . \Config::get('db.' . \Config::get('environment') . '.connection.database') . '.</code>');
         Error::set(CRUDE_SOLUTION, 'There must be at least one table in the configured database for Crude CRUD to work.');
         return false;
     }
     return true;
 }
开发者ID:niceboy120,项目名称:crude,代码行数:37,代码来源:init.php

示例2: compile

 /**
  * Compile the SQL partial for a JOIN statement and return it.
  *
  * @param   mixed  Database instance or instance name
  * @return  string
  */
 public function compile($db = null)
 {
     if (!$db instanceof \Database_Connection) {
         // Get the database instance
         $db = \Database_Connection::instance($db);
     }
     if ($this->_type) {
         $sql = strtoupper($this->_type) . ' JOIN';
     } else {
         $sql = 'JOIN';
     }
     // Quote the table name that is being joined
     $sql .= ' ' . $db->quote_table($this->_table) . ' ON ';
     $conditions = array();
     foreach ($this->_on as $condition) {
         // Split the condition
         list($c1, $op, $c2) = $condition;
         if ($op) {
             // Make the operator uppercase and spaced
             $op = ' ' . strtoupper($op);
         }
         // Quote each of the identifiers used for the condition
         $conditions[] = $db->quote_identifier($c1) . $op . ' ' . $db->quote_identifier($c2);
     }
     // Concat the conditions "... AND ..."
     $sql .= '(' . implode(' AND ', $conditions) . ')';
     return $sql;
 }
开发者ID:gilyaev,项目名称:framework-bench,代码行数:34,代码来源:join.php

示例3: _init

 public static function _init()
 {
     \Config::load('debtsolv', 'debtsolv');
     static::$_debtsolv_database = \Config::get('debtsolv.debtsolv_database', static::$_debtsolv_database);
     static::$_leadpool_database = \Config::get('debtsolv.leadpool_database', static::$_leadpool_database);
     static::$_connection = \Database_Connection::instance('Debtsolv', \Config::get('debtsolv.connection', static::$_connection));
 }
开发者ID:ClixLtd,项目名称:pccupload,代码行数:7,代码来源:debtsolv.php

示例4: compile

 /**
  * Compile the SQL query and return it.
  *
  * @param   mixed  Database instance or instance name
  * @return  string
  */
 public function compile($db = null)
 {
     if (!$db instanceof \Database_Connection) {
         // Get the database instance
         $db = \Database_Connection::instance($db);
     }
     // Start an update query
     $query = 'UPDATE ' . $db->quote_table($this->_table);
     if (!empty($this->_join)) {
         // Add tables to join
         $query .= ' ' . $this->_compile_join($db, $this->_join);
     }
     // Add the columns to update
     $query .= ' SET ' . $this->_compile_set($db, $this->_set);
     if (!empty($this->_where)) {
         // Add selection conditions
         $query .= ' WHERE ' . $this->_compile_conditions($db, $this->_where);
     }
     if (!empty($this->_order_by)) {
         // Add sorting
         $query .= ' ' . $this->_compile_order_by($db, $this->_order_by);
     }
     if ($this->_limit !== NULL && substr($db->_db_type, 0, 6) !== 'sqlite') {
         // Add limiting
         $query .= ' LIMIT ' . $this->_limit;
     }
     return $query;
 }
开发者ID:cloudetm,项目名称:development,代码行数:34,代码来源:update.php

示例5: get_database_results

 private function get_database_results($id)
 {
     $database_query = Model_Database_Query::find($id);
     $config = array('type' => 'pdo', 'connection' => array('dsn' => ($database_query->database_servers->type == 'mysql' ? 'mysql' : 'dblib') . ':host=' . $database_query->database_servers->hostname . ($database_query->database_servers->type == 'mysql' ? ';port=' : ':') . $database_query->database_servers->port . ';dbname=' . $database_query->database, 'username' => $database_query->username == '' ? $database_query->database_servers->username : $database_query->username, 'password' => $database_query->password == '' ? $database_query->database_servers->password : $database_query->password, 'persistent' => false), 'Identifier' => '', 'Charset' => '');
     $remote_connection = Database_Connection::instance('runQuery' . $database_query->database_servers->hostname, $config);
     $results = DB::query($database_query->query)->cached($database_query->cache_time)->execute($remote_connection);
     return $results->as_array();
 }
开发者ID:ClixLtd,项目名称:pccupload,代码行数:8,代码来源:query.php

示例6: execute

 public function execute($db = NULL, $as_object = FALSE)
 {
     if (!is_object($db)) {
         $db = \Database_Connection::instance();
     }
     $type = strtoupper(array_search(get_class($this->command), $this->commands));
     $return = $db->query($type, $this, $as_object);
     return $return;
 }
开发者ID:sakuraiyuta,项目名称:fuel-orientdb,代码行数:9,代码来源:Query.php

示例7: setup

 /**
  * Setup the test
  */
 public function setup()
 {
     \Package::load('hybrid');
     $acl = Acl::make('mock');
     $acl->add_roles('guest');
     $acl->add_resources(array('blog', 'forum', 'news'));
     $acl->allow('guest', array('blog'), 'view');
     $acl->deny('guest', 'forum');
     try {
         \Database_Connection::instance(\Config::get('db.active'))->connect();
     } catch (\Database_Exception $e) {
         // in case when list table is not supported by Database Connection
         $this->markTestSkipped('User table is not available');
     }
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:18,代码来源:acl.php

示例8: action_addProduct

 public function action_addProduct()
 {
     $validator = $this->addModifyValidator();
     $message = "";
     $categories_db = Model_Category::find('all');
     foreach ($categories_db as $category) {
         $categories[$category->id] = $category->name;
     }
     $category_id = Input::post('category_id');
     $description = Input::post('description');
     $image = Input::post('image');
     $doit = Input::post('doit');
     if (!is_null($doit)) {
         try {
             if (!$validator->run(Input::post())) {
                 throw new Exception();
             }
             $valid = (object) $validator->validated();
             $product = Model_Product::forge();
             $product->name = $valid->name;
             $product->price = $valid->price;
             $product->category_id = $category_id;
             $product->description = $description;
             $product->image = $image;
             $product->save();
             return Response::redirect("/home/productInfo/{$product->id}");
             /* 
                 if (strlen($name) < 3) {
                   throw new Exception("name must have at least 3 chars");
                 }
                 if (!preg_match($pattern, $price)) {
                   throw new Exception("illegal price format");
                 }*/
         } catch (Database_Exception $ex) {
             // this gets the message without the extra info
             list(, , $message) = Database_Connection::instance()->error_info();
         } catch (Exception $ex) {
             $message = $ex->getMessage();
         }
     }
     $data = ['message' => $message, 'categories' => $categories];
     $view = View::forge('admin/addProduct.tpl', $data);
     $view->set('validator', $validator, false);
     return Response::forge($view);
 }
开发者ID:AlanMasciangelo,项目名称:FuelPHPStore,代码行数:45,代码来源:admin.php

示例9: initialize

 function initialize()
 {
     define('DOCROOT', realpath(__DIR__ . '/public/') . DIRECTORY_SEPARATOR);
     define('APPPATH', realpath(__DIR__ . '/fuel/app/') . DIRECTORY_SEPARATOR);
     define('PKGPATH', realpath(__DIR__ . '/fuel/packages/') . DIRECTORY_SEPARATOR);
     define('COREPATH', realpath(__DIR__ . '/fuel/core/') . DIRECTORY_SEPARATOR);
     defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
     defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());
     if (!file_exists(COREPATH . 'classes' . DIRECTORY_SEPARATOR . 'autoloader.php')) {
         die('No composer autoloader found. Please run composer to install the FuelPHP framework dependencies first!');
     }
     require COREPATH . 'classes' . DIRECTORY_SEPARATOR . 'autoloader.php';
     class_alias('Fuel\\Core\\Autoloader', 'Autoloader');
     require APPPATH . 'bootstrap.php';
     require_once APPPATH . 'classes/model/Model_Author.php';
     require_once APPPATH . 'classes/model/Model_Book.php';
     $this->con = \Database_Connection::instance()->connection();
     $this->initTables();
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:19,代码来源:FuelTestSuite.php

示例10: _setDebtsolvDatabase

 private function _setDebtsolvDatabase()
 {
     // -- Get the Alias of the company based on Company ID
     // ---------------------------------------------------
     $result = \DB::query("SELECT\n                             alias\n                            ,active\n                           FROM\n                             clientarea_companies\n                           WHERE\n                             id = " . (int) $this->_companyID . "\n                           LIMIT 1                           \n                          ", \DB::select())->execute()->as_array();
     if (isset($result[0]['alias'])) {
         $this->_companyAlias = $result[0]['alias'];
         $this->_active = $result[0]['active'];
         \Config::load('clientarea', 'debtsolv');
         $this->_debtsolvDatabase = \Config::get('debtsolv.' . $this->_companyAlias . '.debtsolv_db', $this->_debtsolvDatabase);
         $this->_leadpoolDatabase = \Config::get('debtsolv.' . $this->_companyAlias . '.leadpool_db', $this->_leadpoolDatabase);
         $this->_connection = \Database_Connection::instance('Debtsolv', \Config::get('debtsolv.' . $this->_companyAlias . '.database', $this->_connection));
         if ($this->_connection instanceof \Database_Connection) {
             \Log::info('CLIENT AREA: Database connected for for Company ' . $this->_companyAlias . ' ID: ' . $this->_companyID . ' DS Name: ' . $this->_debtsolvDatabase);
         } else {
             \Log::error('CLIENT AREA: Failed to connect to ' . $this->_companyAlias);
         }
     } else {
         \Log::error('CLIENT AREA: Failed to connect to company ID ' . (int) $this->_companyID);
     }
 }
开发者ID:ClixLtd,项目名称:pccupload,代码行数:21,代码来源:database.php

示例11: compile

 /**
  * Compile the SQL query and return it.
  *
  * @param mixed $db
  *        	Database_Connection instance or instance name
  *        	
  * @return string
  */
 public function compile($db = null)
 {
     if (!$db instanceof \Database_Connection) {
         // Get the database instance
         $db = \Database_Connection::instance($db);
     }
     // Start a deletion query
     $query = 'DELETE FROM ' . $db->quote_table($this->_table);
     if (!empty($this->_where)) {
         // Add deletion conditions
         $query .= ' WHERE ' . $this->_compile_conditions($db, $this->_where);
     }
     if (!empty($this->_order_by)) {
         // Add sorting
         $query .= ' ' . $this->_compile_order_by($db, $this->_order_by);
     }
     if ($this->_limit !== NULL && substr($db->_db_type, 0, 6) !== 'sqlite') {
         // Add limiting
         $query .= ' LIMIT ' . $this->_limit;
     }
     return $query;
 }
开发者ID:vienbk91,项目名称:fuelphp17,代码行数:30,代码来源:delete.php

示例12: execute

 /**
  * Execute the current query on the given database.
  *
  * @param   mixed    Database instance or name of instance
  * @return  object   Database_Result for SELECT queries
  * @return  mixed    the insert id for INSERT queries
  * @return  integer  number of affected rows for all other queries
  */
 public function execute($db = null)
 {
     if (!is_object($db)) {
         // Get the database instance
         $db = \Database_Connection::instance($db);
     }
     // Compile the SQL query
     $sql = $this->compile($db);
     switch (strtoupper(substr(ltrim($sql, '('), 0, 6))) {
         case 'SELECT':
             $this->_type = \DB::SELECT;
             break;
         case 'INSERT':
         case 'CREATE':
             $this->_type = \DB::INSERT;
             break;
     }
     if ($db->caching() and !empty($this->_lifetime) and $this->_type === DB::SELECT) {
         $cache_key = empty($this->_cache_key) ? 'db.' . md5('Database_Connection::query("' . $db . '", "' . $sql . '")') : $this->_cache_key;
         if (is_string($this->_cache_key) && substr($this->_cache_key, -1) == '.') {
             $cache_key = $this->_cache_key . md5('Database_Connection::query("' . $db . '", "' . $sql . '")');
         }
         $cache = \Cache::forge($cache_key);
         try {
             $result = $cache->get();
             return new Database_Result_Cached($result, $sql, $this->_as_object);
         } catch (CacheNotFoundException $e) {
         }
     }
     // Execute the query
     \DB::$query_count++;
     $result = $db->query($this->_type, $sql, $this->_as_object);
     // Cache the result if needed
     if (isset($cache) and ($this->_cache_all or $result->count())) {
         $cache->set_expiration($this->_lifetime)->set_contents($result->as_array())->set();
     }
     return $result;
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:46,代码来源:query.php

示例13: table_exists

 /**
  * Checks if a given table exists.
  *
  * @param   string  $table  Table name
  * @return  bool
  */
 public static function table_exists($table, $db = null)
 {
     try {
         \DB::select()->from($table)->limit(1)->execute($db ? $db : static::$connection);
         return true;
     } catch (\Database_Exception $e) {
         // check if we have a DB connection at all
         $connection = \Database_Connection::instance($db ? $db : static::$connection)->connection();
         // if no connection could be made, re throw the exception
         if (!$connection) {
             throw $e;
         }
         return false;
     }
 }
开发者ID:wushian,项目名称:MDD,代码行数:21,代码来源:dbutil.php

示例14: compile

 /**
  * Compile the SQL query and return it.
  *
  * @param   mixed  $db  Database instance or instance name
  *
  * @return  string
  */
 public function compile($db = null)
 {
     if (!$db instanceof \Database_Connection) {
         // Get the database instance
         $db = \Database_Connection::instance($db);
     }
     // Start an insertion query
     $query = 'INSERT INTO ' . $db->quote_table($this->_table);
     // Add the column names
     $query .= ' (' . implode(', ', array_map(array($db, 'quote_identifier'), $this->_columns)) . ') ';
     if (is_array($this->_values)) {
         // Callback for quoting values
         $quote = array($db, 'quote');
         $groups = array();
         foreach ($this->_values as $group) {
             foreach ($group as $i => $value) {
                 if (is_string($value) and isset($this->_parameters[$value])) {
                     // Use the parameter value
                     $group[$i] = $this->_parameters[$value];
                 }
             }
             $groups[] = '(' . implode(', ', array_map($quote, $group)) . ')';
         }
         // Add the values
         $query .= 'VALUES ' . implode(', ', $groups);
     } else {
         // Add the sub-query
         $query .= (string) $this->_values;
     }
     return $query;
 }
开发者ID:SainsburysTests,项目名称:sainsburys,代码行数:38,代码来源:insert.php

示例15: rollback_transaction

	/**
	 * Rollsback all pending transactional queries
	 *
	 *     DB::rollback_transaction();
	 *
	 * @param   string  db connection
	 * @return  void
	 */
	public static function rollback_transaction($db = null)
	{
		return \Database_Connection::instance($db)->rollback_transaction();
	}
开发者ID:novius,项目名称:core,代码行数:12,代码来源:db.php


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