private function open_con() { if (isset($this->db)) { $this->db = db::getConnection(); } //parent::getConnection(); }
public static function getTotalProductsInCategory($categoryId) { $db = db::getConnection(); $result = $db->query('SELECT count(id) AS count FROM product ' . 'WHERE status = "1" AND category_id = "' . $categoryId . '"'); $result->setFetchMode(PDO::FETCH_ASSOC); $row = $result->fetch(); return $row['count']; }
private function db_con() { if (!isset($this->db)) { $this->db = db::getConnection(); } if ($this->db->connect_error) { //header('Location: '.SITE_URL); } }
function open_con() { if (!isset($this->mysqli)) { @($this->mysqli = db::getConnection()); if ($this->mysqli->connect_error) { die($this->mysqli->error); } } }
function __construct($scode = NULL) { require_once 'useragent/UASparser.php'; $this->mysqli = db::getConnection(); if ($this->mysqli->connect_error) { die("Database error ,cant connect"); } $this->shortcode = $scode; $this->uaparse = new UAS\Parser(__DIR__ . '/useragent/uascache/', null, false, true); $this->cbua = $this->ClickByUserAgent(); }
public static function getCategoriesList() { $db = db::getConnection(); $categoryList = array(); $result = $db->query('SELECT id, name FROM category ORDER BY sort_order ASC'); $i = 0; while ($row = $result->fetch()) { $categoryList[$i]['id'] = $row['id']; $categoryList[$i]['name'] = $row['name']; $i++; } return $categoryList; }
public static function getNewsList() { try { $db = db::getConnection(); //Вызов статического метода для подключения к БД } catch (PDOException $e) { echo 'Не получилось подключиться к БД '; echo $e->getMessage(); die; } $newsList = array(); //массив результатов //С помощью подключения к БД выполныется запрос к БД на вывод данных из таблици news, с сортировкой по дате, и на лимит в 10 строк $result = $db->query('SELECT id, title, date, short_content FROM news ORDER BY date DESC LIMIT 10'); $i = 0; while ($row = $result->fetch()) { $newsList[$i]['id'] = $row['id']; $newsList[$i]['title'] = $row['title']; $newsList[$i]['date'] = $row['date']; $newsList[$i]['short_content'] = $row['short_content']; $i++; } return $newsList; }
<?php /** * Created by PhpStorm. * User: Dahmani Alae * Date: 11/13/2015 * Time: 2:12 PM */ require '../vendor/autoload.php'; require 'Config.php'; use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); $db = new db(); $conn = $db->getConnection(); $data = json_decode($request->getContent()); $nom = $data->nom_secteur; $stmt = $conn->prepare('insert into secteur(nom_secteur) values(:nom)'); $stmt->bindParam(':nom', $nom); $stmt->execute(); $id = $conn->lastInsertId(); /** * add on sous secteur table */ $stt = $conn->prepare('insert into sous_secteur(nom_sous_secteur,id_secteur) values(:noms,:id)'); $var = array(); $var = $data->list_sous_secteur; $stt->bindParam(':id', $id); foreach ($var as $key) { $stt->bindParam(':noms', $key); $stt->execute(); }
<?php # loader Nix libraries require_once '../../src/Nix/loader.php'; use Nix\Debugging\Debugger, Nix\Database\Db; Debugger::init(true); Debugger::setLogPath(__DIR__ . '/../temp/'); Db::connect(array('database' => 'nix_examples')); echo '<h2>escaping</h2>'; $a = array('test%r' => 'Now()', 'tests%s' => 'SuperTest\'', 'tsadst' => true); dump(db::getConnection()->escapeArray($a)); echo '<h2>fetch field</h2>'; dump(Db::fetchField("select [name] from [albums] order by RAND() limit 1")); echo '<h2>fetch all</h2>'; dump(Db::fetchAll("select * from [albums] order by [name] limit 3")); echo '<h2>fetch pairs</h2>'; dump(Db::fetchPairs("select [id], [name] from [albums] order by RAND() limit 10")); echo '<h2>fetch pairs</h2>'; dump(Db::fetchPairs("select [name] from [albums] order by RAND() limit 10"));
/** *Returns user by id *@param integer $id **/ public static function getUserById($id) { if ($id) { $db = db::getConnection(); $sql = 'SELECT * FROM user WHERE id = :id'; $result = $db->prepare($sql); $result->bindParam(':id', $id, PDO::PARAM_INT); //Указываем что хотим получить данные в виде массива $result->setFetchMode(PDO::FETCH_ASSOC); $result->execute(); return $result->fetch(); } }
public function __construct() { parent::__construct(); $this->pdo = parent::getConnection(); }