function pullVisits($date = null) { $date or $date = static::today(); $query = $this->adapter->getDataQuery()->addMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_VISITORS)->addMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)->addMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->addMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_UNIQUE_PAGEVIEWS)->addDimension(\Zend_Gdata_Analytics_DataQuery::DIMENSION_DATE)->addSort(\Zend_Gdata_Analytics_DataQuery::DIMENSION_DATE)->setStartDate($date)->setEndDate($date); $result = $this->adapter->getDataFeed($query); $found = $result->count(); $updated = 0; foreach ($result as $r) { try { \DB::pdo()->executeQuery(static::QUERY, array('created' => $date, 'name' => 'visit', 'countTotal' => @$r->getMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)->getValue(), 'countUnique' => @$r->getMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_VISITORS)->getValue())); $updated++; } catch (\Exception $unimportant) { if ($unimportant->getCode() != 23000) { \Zend_Registry::get('log')->err($unimportant->getMessage()); } } try { \DB::pdo()->executeQuery(static::QUERY, array('created' => $date, 'name' => 'pageview', 'countTotal' => @$r->getMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->getValue(), 'countUnique' => @$r->getMetric(\Zend_Gdata_Analytics_DataQuery::METRIC_UNIQUE_PAGEVIEWS)->getValue())); $updated++; } catch (\Exception $unimportant) { if ($unimportant->getCode() != 23000) { \Zend_Registry::get('log')->err($unimportant->getMessage()); } } } return array('itemsFound' => $found, 'itemsUpdated' => $updated); }
public static function singleton() { if (!is_object(self::$pdo)) { self::$pdo = new PDO('mysql:dbname=' . self::DATABASE . ';host=' . self::HOST, self::USERNAME, self::PASSWORD); } return self::$pdo; }
public static function getInstance() { if (is_null(self::$pdo)) { self::$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_BASE, DB_USER, DB_PASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); } return self::$pdo; }
/** * open connect to database * @param string $host dbhost * @param string $login database user's login * @param string $pass database user's password * @param string $name database's name * @param string $charset database's charset * @throws DatabaseException if it has connection error */ public static function connect($host, $login, $pass, $name, $charset) { $dsn = "mysql:host={$host};dbname={$name}"; try { self::$pdo = new PDO($dsn, $login, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES {$charset}")); } catch (PDOException $e) { throw new DatabaseException("Connection error"); } }
public static function init() { self::$pdo = new PDO('mysql:host=' . SERVER . ';dbname=' . DBNAME, USER, PASS); self::$pdo->exec("SET NAMES 'UTF8'"); self::$pdo->exec("SET character_set_connection = 'UTF8'"); self::$pdo->exec("SET character_set_client = 'UTF8'"); self::$pdo->exec("SET character_set_results = 'UTF8'"); self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); return self::$pdo; }
public static function get() { if (self::$pdo == null) { $host = DB_HOST; $dbname = DB_NAME; $dbuser = DB_USER; $dbpass = DB_PASSWORD; self::$pdo = new PDO("mysql:host={$host};dbname={$dbname}", $dbuser, $dbpass); self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$pdo; }
public static function getPDO() { if (is_null(self::$pdo)) { // $dsn = 'mysql:dbname=papangping_nai;host=localhost'; // $user = '******'; // $password = '******'; $dsn = 'mysql:dbname=nai;host=localhost'; $user = '******'; $password = '******'; self::$pdo = new PDO($dsn, $user, $password); self::$pdo->exec("set names utf8"); } return self::$pdo; }
static function init() { if (self::$pdo !== null) { return; } global $global; if (!isset($global['db'])) { exit('classic case of no db definition found'); } extract($global['db']); try { self::$pdo = new PDO("mysql:host={$host};dbname={$db}", $user, $pass); } catch (PDOException $e) { throw new Exception('Could not connect to database: ' . $e->getMessage()); } register_shutdown_function(function () { // auto close database connection upon script termination so mysql can shove a cock in its ass self::$pdo = null; }); return self::$pdo !== null; }
/** * Author: UP687776 * Web Script Programming * Rich Boakes && Kit Lester * 2014 && 2015 */ require 'DBConnect/db.php'; class products { public $ProductID; public $CategoryID; public $ProductName; public $ProductDescription; public $ProductPrice; public $ProductStockLevel; public $ProductImage; } $search = $_GET["input"]; try { $database = new DB(); $bind = null; $sql = "SELECT * FROM Products WHERE ProductName LIKE :searchterm"; $a = $database->pdo()->prepare($sql); $a->execute(array(":searchterm" => "%" . $search . "%")); $rows = $a->fetchAll(PDO::FETCH_CLASS, "products"); foreach ($rows as $row) { print "<section class='layout'><p>ProductID: " . $row->ProductID . "</p><h4> " . $row->ProductName . "</h4><p class='writeUp'>" . $row->ProductDescription . "</p><p class='writeUp'>£" . $row->ProductPrice . "</p><p class='writeUp'>Stock Level:" . $row->ProductStockLevel . "</p><img class='productImage' src=../images/productImages/" . $row->ProductImage . "><button id=" . $row->ProductID . "> Add To Cart </button></section>"; } } catch (PDOException $e) { echo $e; }
/** * Sets up the driver and the PDO connection. * * @access public * @static */ public static function setup() { // connect to the DB self::$pdo = new PDO(strtolower(Reg::get("Database.driver")) . ':host=' . Reg::get('Database.host') . ';dbname=' . Reg::get('Database.database'), Reg::get('Database.username'), Reg::get('Database.password'), array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); // load the driver $specific_driver = Reg::get("Database.driver"); $driver_name = "DB_{$specific_driver}_Driver"; self::$driver = new $driver_name(); }
public function __construct() { DB::$pdo = new PDO('mysql:host=' . BDHOST . ';dbname=' . BDNAME . '', BDLOGIN, BDPASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); }
public static function connect(Config $config) { self::$pdo = new PDO("mysql:host=" . $config->dbHost . ";dbname=" . $config->dbName, $config->dbUser, $config->dbPass); }
protected function getConnection() { return $this->createDefaultDBConnection(DB::pdo(), 'testdb'); }
/** * Update Product Function * Receive record in JASON Formatted String from client side and decode it and convert the product into an object which can go onto the database * The "php://input" allows the user to read raw POST data. * @parameter: ProductID: update the record/product by specifying produc id * var_dump displays information about one or more expression (productName and productPrice) * Create new database if it doesn't exists */ function updateProducts($ProductID) { $info = json_decode(file_get_contents("php://input"), true); $database = new DB(); var_dump(file_get_contents("php://input")); $sql = "UPDATE Products SET ProductName = '" . $info['ProductName'] . "', Price = '" . $info['ProductPrice'] . "' WHERE ProductID = {$ProductID}"; $a = $database->pdo()->prepare($sql); $a->execute(); }