public function verifyLogin($username, $password) { $mysql = getMySQLConnection(); $query = $mysql->prepare("SELECT id FROM administrator WHERE username = :username AND password_hash = :password_hash"); $query->execute(['username' => $username, 'password_hash' => sha1($password)]); $is_login_successful = $query->rowCount() == 1; return $is_login_successful; }
public function getAllCategories() { $mysql = getMySQLConnection(); $language_fields_addition = $_SESSION['language'] == 'en_US' ? '' : '_' . $_SESSION['language']; $query = $mysql->prepare("SELECT * FROM category ORDER BY name" . $language_fields_addition); $query->execute(); return $query->fetchAll(PDO::FETCH_CLASS, 'Category'); }
public function insert($product_id, $timestamp, $browser_id) { $mysql = getMySQLConnection(); $prep = $mysql->prepare("INSERT INTO purchase (product_id,timestamp,browser_id)\n\t\t\t\tVALUES (:product_id,:timestamp,:browser_id)"); $prep->bindParam(':product_id', $product_id); $prep->bindParam(':timestamp', $timestamp); $prep->bindParam(':browser_id', $browser_id); $prep->execute(); }
public function __construct($id = null) { $this->_mysql = getMySQLConnection(); $this->_mongodb = DBConnection::instantiate(); $this->_collection = $this->_mongodb->getCollection('customer_metadata'); $this->_table = 'customers'; if (isset($id)) { $this->_id = $id; $this->_load(); } }
public function getbyCategoryid($category_id) { $mysql = getMySQLConnection(); $language_fields_addition = $_SESSION['language'] == 'en_US' ? '' : '_' . $_SESSION['language']; $query = $mysql->prepare("SELECT * FROM specification WHERE category_id = :category_id"); $query->execute(['category_id' => $category_id]); if ($query->rowCount() > 0) { return $query->fetchAll(PDO::FETCH_CLASS, 'Specification'); } else { return false; } }
<?php require 'mysql.php'; require 'dbconnection.php'; $cutoffDate = date('Y-m-d', strtotime('-30 day')); $mysql = getMySQLConnection(); $query = sprintf("SELECT * FROM sales WHERE DATE(time_of_sales) < '%s'", $cutoffDate); printf("Fetching old data from MySQL...\n"); $result = $mysql->query($query); if ($result === False) { die(sprintf("Error executing query %s" % $mysql->error)); } printf("Migrating to MongoDB...\n"); $mongo = DBConnection::instantiate(); $collection = $mongo->getCollection('sales_archive'); while ($record = $result->fetch_assoc()) { try { $collection->insert($record, array('safe' => True)); } catch (MongoCursorException $e) { die("Migration Failed " . $e->getMessage()); } } printf("\tDone. %d records migrated.\n", $result->num_rows); $result->free(); printf("Deleting old data from MySQL...\n"); $query = sprintf("DELETE FROM sales WHERE DATE(time_of_sales) < '%s'", $cutoffDate); $status = $mysql->query($query); if ($status === False) { die(sprintf("Error executing query %s" % $mysql->error)); } $mysql->close();
/** * @param array $mysqlOptions * @param int $lastActiveTimestamp * * @return array */ function onShard(array $mysqlOptions, $lastActiveTimestamp) { $pdo = getMySQLConnection($mysqlOptions); if ($pdo === false) { return []; } PHP_Timer::start(); $uidList = fetchActiveUidList($pdo, $lastActiveTimestamp); $timeCost = PHP_Timer::secondsToTimeString(PHP_Timer::stop()); appendLog('fetchActiveUidList cost ' . $timeCost . ' to get result set of size = ' . count($uidList)); if (count($uidList) === 0) { return []; } PHP_Timer::start(); $details = readUserInfo($pdo, $uidList, 50); $timeCost = PHP_Timer::secondsToTimeString(PHP_Timer::stop()); appendLog('readUserInfo cost ' . $timeCost); return $details; }
public function avgPriceByCategory($category_id) { $mysql = getMySQLConnection(); $query = $mysql->prepare("SELECT AVG(purchase_price) AS avgprice FROM product WHERE category_id = :category_id"); $query->execute(['category_id' => $category_id]); return $query->fetch()['avgprice']; }
public function updateByName($name, $variable_1, $variable_2) { $mysql = getMySQLConnection(); $query = $mysql->prepare("UPDATE formulas SET variable_1 = :variable_1, variable_2 = :variable_2 WHERE name LIKE :name"); return $query->execute(['name' => $name, 'variable_1' => $variable_1, 'variable_2' => $variable_2]); }
public function delete($id) { $mysql = getMySQLConnection(); $query = $mysql->prepare("DELETE FROM translations WHERE id = :id"); return $query->execute(['id' => $id]); }