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;
 }
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;
}
 protected function __init()
 {
     $this->loadlib('database');
     $db = new Database_Connection();
     // create new db connection
     $cid = $db->connect("mysql://*****:*****@localhost/test");
     // connect
     $this->loadLib('sessions');
     // load lib
 }
Exemple #4
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #6
0
 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));
 }
Exemple #7
0
 /**
  * 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;
 }
Exemple #8
0
 /**
  * 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;
 }
Exemple #9
0
 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();
 }
Exemple #10
0
 protected function __construct($name, array $config)
 {
     parent::__construct($name, $config);
     if (isset($this->_config['identifier'])) {
         // Allow the identifier to be overloaded per-connection
         $this->_identifier = (string) $this->_config['identifier'];
     }
 }
Exemple #11
0
 /**
  * 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;
 }
Exemple #12
0
 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;
 }
Exemple #13
0
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;
    }
}
Exemple #14
0
 /**
  * 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');
     }
 }
 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);
 }
 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();
 }
Exemple #17
0
 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);
     }
 }
Exemple #18
0
 /**
  * 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;
 }
Exemple #19
0
 /**
  * Deletes the entire tree structure using the current node as starting point
  *
  * @param   mixed  $cascade
  *     null = use default config,
  *     bool = force/prevent cascade,
  *     array cascades only the relations that are in the array
  * @return  Model  this instance as a new object without primary key(s)
  */
 public function delete_tree($cascade = null, $use_transaction = false)
 {
     if ($use_transaction) {
         $db = \Database_Connection::instance(static::connection(true));
         $db->start_transaction();
     }
     // get params to avoid excessive method calls
     $left_field = static::tree_config('left_field');
     $right_field = static::tree_config('right_field');
     $pk = reset(static::$_primary_key);
     // put the entire operation in a try/catch, so we can rollback if needed
     try {
         // check if the node has children
         if ($this->has_children()) {
             // get them
             $children = $this->children()->get();
             // and delete them to
             foreach ($children as $child) {
                 if ($child->delete_tree($cascade) === false) {
                     throw new \UnexpectedValueException('delete of child node with PK "' . $child->{$pk} . '" failed.');
                 }
             }
         }
         // delete the node itself
         $result = parent::delete($cascade);
         // check if the delete was succesful
         if ($result !== false) {
             // re-index the tree
             $this->_shift_rl_values($this->{$right_field} + 1, $this->{$left_field} - $this->{$right_field} - 1);
         }
     } catch (\Exception $e) {
         $use_transaction and $db->rollback_transaction();
         throw $e;
     }
     // reset the node operation store to make sure nothings pending...
     $this->_node_operation = array();
     // and return the result
     return $result;
 }
Exemple #20
0
 /**
  * Get the minimum of a column for the current query
  *
  * @param   string  column
  * @return  mixed   minimum value OR false
  */
 public function min($column)
 {
     is_array($column) and $column = array_shift($column);
     // Get the columns
     $columns = \DB::expr('MIN(' . \Database_Connection::instance()->table_prefix() . $this->alias . '.' . $column . ') AS min_result');
     // Remove the current select and
     $query = call_user_func('DB::select', $columns);
     // Set from table
     $query->from(array(call_user_func($this->model . '::table'), $this->alias));
     $tmp = $this->build_query($query, $columns, 'min');
     $query = $tmp['query'];
     $min = $query->execute($this->connection)->get('min_result');
     // Database_Result::get('min_result') returns a string | null
     if ($min === null) {
         return false;
     }
     return $min;
 }
Exemple #21
0
 /**
  * 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);
     }
     // Callback to quote identifiers
     $quote_ident = array($db, 'quote_identifier');
     // Callback to quote tables
     $quote_table = array($db, 'quote_table');
     // Start a selection query
     $query = 'SELECT ';
     if ($this->_distinct === TRUE) {
         // Select only unique results
         $query .= 'DISTINCT ';
     }
     if (empty($this->_select)) {
         // Select all columns
         $query .= '*';
     } else {
         // Select all columns
         $query .= implode(', ', array_unique(array_map($quote_ident, $this->_select)));
     }
     if (!empty($this->_from)) {
         // Set tables to select from
         $query .= ' FROM ' . implode(', ', array_unique(array_map($quote_table, $this->_from)));
     }
     if (!empty($this->_join)) {
         // Add tables to join
         $query .= ' ' . $this->_compile_join($db, $this->_join);
     }
     if (!empty($this->_where)) {
         // Add selection conditions
         $query .= ' WHERE ' . $this->_compile_conditions($db, $this->_where);
     }
     if (!empty($this->_group_by)) {
         // Add sorting
         $query .= ' GROUP BY ' . implode(', ', array_map($quote_ident, $this->_group_by));
     }
     if (!empty($this->_having)) {
         // Add filtering conditions
         $query .= ' HAVING ' . $this->_compile_conditions($db, $this->_having);
     }
     if (!empty($this->_order_by)) {
         // Add sorting
         $query .= ' ' . $this->_compile_order_by($db, $this->_order_by);
     }
     if ($this->_limit !== NULL) {
         // Add limiting
         $query .= ' LIMIT ' . $this->_limit;
     }
     if ($this->_offset !== NULL) {
         // Add offsets
         $query .= ' OFFSET ' . $this->_offset;
     }
     return $query;
 }
Exemple #22
0
 /**
  * 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;
     }
 }
 /**
  * 完了画面
  *
  * @access public
  * @param
  * @return void
  * @author kobayashi
  */
 public function post_thanks()
 {
     if (!Security::check_token()) {
         \Response::redirect('errors/doubletransmission');
     }
     try {
         $db = \Database_Connection::instance('master');
         $db->start_transaction();
         $fleamarket = $this->registerFleamarket();
         $files = $this->storeImages($fleamarket->fleamarket_id);
         if ($files) {
             $this->registerFleamarketImage($fleamarket, $files);
         }
         $this->removeFleamarketImages();
         $this->registerFleamarketAbout($fleamarket);
         $this->registerFleamarketEntryStyle($fleamarket);
         $db->commit_transaction();
     } catch (Exception $e) {
         $db->rollback_transaction();
         throw $e;
     }
     $view = View::forge('admin/fleamarket/thanks');
     $this->template->content = $view;
 }
Exemple #24
0
 /**
  * Get the minimum of a column for the current query
  *
  * @param   string      $column Column which min value you want to get
  *
  * @return  bool|int    minimum value OR false
  */
 public function min($column)
 {
     is_array($column) and $column = array_shift($column);
     // Get the columns
     $columns = \DB::expr('MIN(' . \Database_Connection::instance($this->connection)->quote_identifier($this->alias . '.' . $column) . ') AS min_result');
     // Remove the current select and
     $query = \DB::select($columns);
     // Set from table
     $query->from(array($this->_table(), $this->alias));
     $tmp = $this->build_query($query, $columns, 'min');
     $query = $tmp['query'];
     $min = $query->execute($this->connection)->get('min_result');
     // Database_Result::get('min_result') returns a string | null
     if ($min === null) {
         return false;
     }
     return $min;
 }
Exemple #25
0
 /**
  * Count all of the rows in the table.
  *
  * @param   string  Column to count by
  * @param   bool    Whether to count only distinct rows (by column)
  * @param   array   Query where clause(s)
  * @param   string  Column to group by
  * @return  int     The number of rows OR false
  */
 public static function count($column = null, $distinct = true, $where = array(), $group_by = null)
 {
     $select = $column ?: static::primary_key();
     // Get the database group / connection
     $connection = static::get_connection();
     // Get the columns
     $columns = \DB::expr('COUNT(' . ($distinct ? 'DISTINCT ' : '') . \Database_Connection::instance($connection)->quote_identifier($select) . ') AS count_result');
     // Remove the current select and
     $query = \DB::select($columns);
     // Set from table
     $query = $query->from(static::$_table_name);
     if (!empty($where)) {
         //is_array($where) or $where = array($where);
         if (!is_array($where) and $where instanceof \Closure === false) {
             throw new \FuelException(get_called_class() . '::count where statement must be an array or a closure.');
         }
         $query = $query->where($where);
     }
     if (!empty($group_by)) {
         $result = $query->select($group_by)->group_by($group_by)->execute($connection)->as_array();
         $counts = array();
         foreach ($result as $res) {
             $counts[$res[$group_by]] = $res['count_result'];
         }
         return $counts;
     }
     $count = $query->execute($connection)->get('count_result');
     if ($count === null) {
         return false;
     }
     return (int) $count;
 }
<?php

#When the user clicks the confirm button in confirm_checkout, this page is called.
#This page...
#	Inserts a new order in the database.
# 	Inserts deliver information and product information related to the order
#	Updates the product stock.
# All of these database actions are done within a commit/rollback so if any of the actions would fail, the database would not commit
# the rest of the actions that did succeed.
include_once 'error/error_handler.php';
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
include_once 'db_data.php';
$db = new Database_Connection();
include_once 'model/confirm_checkout_model.php';
//turns out this page needs just about the exact kind of data...
$p = new Confirm_Checkout();
$data = $p->build();
$order_sql = "INSERT INTO orders(totalprice) VALUES (?)";
$deliver_sql = "INSERT INTO orderdelivery(orderid, firstname, lastname, email, address, zipcode, area) VALUES (?,?,?,?,?,?,?)";
$product_sql = "INSERT INTO orderproducts(orderid, productid) VALUES (?,?)";
$stock_sql = "UPDATE stock SET quantity=? WHERE productsid=?";
$success = false;
try {
    $db->connection->autocommit(false);
    //Insert a new order in the database
    $db->param_query($order_sql, "i", $data['total_price']);
    if ($db->statement->affected_rows == 0) {
        throw new Exception('order_sql not added');
    }
 public function datatype($type)
 {
     static $types = array('blob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '65535'), 'bool' => array('type' => 'bool'), 'bigint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '18446744073709551615'), 'datetime' => array('type' => 'string'), 'decimal unsigned' => array('type' => 'float', 'exact' => true, 'min' => '0'), 'double' => array('type' => 'float'), 'double precision unsigned' => array('type' => 'float', 'min' => '0'), 'double unsigned' => array('type' => 'float', 'min' => '0'), 'enum' => array('type' => 'string'), 'fixed' => array('type' => 'float', 'exact' => true), 'fixed unsigned' => array('type' => 'float', 'exact' => true, 'min' => '0'), 'float unsigned' => array('type' => 'float', 'min' => '0'), 'int unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), 'integer unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), 'longblob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '4294967295'), 'longtext' => array('type' => 'string', 'character_maximum_length' => '4294967295'), 'mediumblob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '16777215'), 'mediumint' => array('type' => 'int', 'min' => '-8388608', 'max' => '8388607'), 'mediumint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '16777215'), 'mediumtext' => array('type' => 'string', 'character_maximum_length' => '16777215'), 'national varchar' => array('type' => 'string'), 'numeric unsigned' => array('type' => 'float', 'exact' => true, 'min' => '0'), 'nvarchar' => array('type' => 'string'), 'point' => array('type' => 'string', 'binary' => true), 'real unsigned' => array('type' => 'float', 'min' => '0'), 'set' => array('type' => 'string'), 'smallint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '65535'), 'text' => array('type' => 'string', 'character_maximum_length' => '65535'), 'tinyblob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '255'), 'tinyint' => array('type' => 'int', 'min' => '-128', 'max' => '127'), 'tinyint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '255'), 'tinytext' => array('type' => 'string', 'character_maximum_length' => '255'), 'varchar' => array('type' => 'string', 'exact' => true), 'year' => array('type' => 'string'));
     $type = str_replace(' zerofill', '', $type);
     if (isset($types[$type])) {
         return $types[$type];
     }
     return parent::datatype($type);
 }
Exemple #28
0
 public function datatype($type)
 {
     // try to determine the datatype
     $datatype = parent::datatype($type);
     // if not an ANSI database, assume it's string
     return empty($datatype) ? array('type' => 'string') : $datatype;
 }
 /**
  * Compiles an array of ORDER BY statements into an SQL partial.
  *
  * @param   object  Database instance
  * @param   array   sorting columns
  * @return  string
  */
 protected function _compile_order_by(\Database_Connection $db, array $columns)
 {
     $sort = array();
     foreach ($columns as $group) {
         list($column, $direction) = $group;
         if (!empty($direction)) {
             // Make the direction uppercase
             $direction = ' ' . strtoupper($direction);
         }
         $sort[] = $db->quote_identifier($column) . $direction;
     }
     return 'ORDER BY ' . implode(', ', $sort);
 }
Exemple #30
0
 /**
  * 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;
 }