本文整理汇总了PHP中db::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP db::getConnection方法的具体用法?PHP db::getConnection怎么用?PHP db::getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db
的用法示例。
在下文中一共展示了db::getConnection方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open_con
private function open_con()
{
if (isset($this->db)) {
$this->db = db::getConnection();
}
//parent::getConnection();
}
示例2: getTotalProductsInCategory
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'];
}
示例3: db_con
private function db_con()
{
if (!isset($this->db)) {
$this->db = db::getConnection();
}
if ($this->db->connect_error) {
//header('Location: '.SITE_URL);
}
}
示例4: open_con
function open_con()
{
if (!isset($this->mysqli)) {
@($this->mysqli = db::getConnection());
if ($this->mysqli->connect_error) {
die($this->mysqli->error);
}
}
}
示例5: __construct
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();
}
示例6: getCategoriesList
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;
}
示例7: getNewsList
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;
}
示例8: db
<?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();
}
示例9: array
<?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"));
示例10: getUserById
/**
*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();
}
}
示例11: __construct
public function __construct()
{
parent::__construct();
$this->pdo = parent::getConnection();
}