當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Database_Connection類代碼示例

本文整理匯總了PHP中Database_Connection的典型用法代碼示例。如果您正苦於以下問題:PHP Database_Connection類的具體用法?PHP Database_Connection怎麽用?PHP Database_Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Database_Connection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: queryAllStoreInfo

 public function queryAllStoreInfo()
 {
     include_once '../Database/Database_Connection.php';
     $databaseConnection = new Database_Connection();
     $databaseConnection->createDatabase();
     $databaseConnection->databaseConnect();
     $sql = "select * from scudsbook_store_info";
     $result = mysqli_query($databaseConnection->conn, $sql);
     $i = 1;
     if ($result->num_rows > 0) {
         // output data of each row
         while ($row = $result->fetch_assoc()) {
             $this->_store_name[$i] = $row['store_name'];
             $this->_store_rating[$i] = $row['store_rating'];
             $this->_store_category[$i] = $row['store_category'];
             $this->_store_location_lat[$i] = $row['store_location_lat'];
             $this->_store_location_lan[$i] = $row['store_location_lan'];
             $this->_default_address_street[$i] = $row['address_street'];
             $this->_default_address_street_ref[$i] = $row['address_ref'];
             $this->_default_address_city[$i] = $row['address_city'];
             $this->_default_address_state[$i] = $row['address_state'];
             $this->_default_address_zip[$i] = $row['address_zip'];
             $this->_default_address_country[$i] = $row['address_country'];
             $i++;
         }
     } else {
         echo "0 results";
     }
     mysqli_close($databaseConnection->conn);
     $databaseConnection->conn_state = false;
 }
開發者ID:scudsbook,項目名稱:project_scudsbook,代碼行數:31,代碼來源:Store_Information.php

示例2: get_stock

function get_stock($id)
{
    $db = new Database_Connection();
    $sql = 'SELECT quantity FROM stock WHERE productsid = ?';
    $result = $db->param_query($sql, 'i', $id);
    $data = $result->fetch_assoc();
    $db->close_statement();
    return !empty($data['quantity']) ? $data['quantity'] : 0;
}
開發者ID:anla9107,項目名稱:E-butik-PHP,代碼行數:9,代碼來源:cart_actions.php

示例3: __init

 protected function __init()
 {
     $this->loadlib('database');
     $db = new Database_Connection();
     // create new db connection
     $cid = $db->connect("mysql://root:whatis321@localhost/test");
     // connect
     $this->loadLib('sessions');
     // load lib
 }
開發者ID:jjanes,項目名稱:Amber-PHP-Application-Framework,代碼行數:10,代碼來源:init.php

示例4: 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

示例5: compile

 /**
  * Compile the SQL query and return it.
  *
  * @param   object  Database instance
  * @return  string
  */
 public function compile(\Database_Connection $db)
 {
     // Start an update query
     $query = 'UPDATE ' . $db->quote_table($this->_table);
     // 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 ($this->_limit !== NULL && substr($db->_db_type, 0, 6) !== 'sqlite') {
         // Add limiting
         $query .= ' LIMIT ' . $this->_limit;
     }
     return $query;
 }
開發者ID:bryanheo,項目名稱:FuelPHP-Auth-AJAX,代碼行數:22,代碼來源:update.php

示例6: _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

示例7: 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

示例8: 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

示例9: 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

示例10: compile

 /**
  * Compile the SQL query and return it.
  *
  * @param   object  Database instance
  * @return  string
  */
 public function compile(\Database_Connection $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:469306621,項目名稱:Languages,代碼行數:24,代碼來源:delete.php

示例11: 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

示例12: add_product

function add_product($id)
{
    try {
        if (session_status() == PHP_SESSION_NONE) {
            session_start();
        }
        $db = new Database_Connection();
        $sql = 'SELECT quantity FROM stock WHERE productsid = ?';
        $result = $db->param_query($sql, 'i', $id);
        $data = $result->fetch_assoc();
        $db->close_statement();
        if ($data['quantity'] < 1) {
            throw new Exception('Product is not in stock');
        }
        $quantity = 0;
        if (!empty($_SESSION['cart'][$id])) {
            $quantity = $_SESSION['cart'][$id];
        }
        $_SESSION['cart'][$id] = ++$quantity;
        return true;
    } catch (Exception $e) {
        return false;
    }
}
開發者ID:anla9107,項目名稱:E-butik-PHP,代碼行數:24,代碼來源:add_product.php

示例13: 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

示例14: 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

示例15: 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


注:本文中的Database_Connection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。