本文整理汇总了PHP中Db::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::getConnection方法的具体用法?PHP Db::getConnection怎么用?PHP Db::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_getConnection
public function test_getConnection()
{
/** === Setup Mocks === */
$this->mResource->shouldReceive('getConnection')->andReturn($this->mConn);
/** === Call and asserts === */
$res = $this->obj->getConnection();
$this->assertInstanceOf(\Magento\Framework\DB\Adapter\AdapterInterface::class, $res);
}
示例2: getNewsList
public static function getNewsList()
{
// Запрос к БД
$conn = Db::getConnection();
$newsList = array();
$sql = 'SELECT id, title, date, short_content ' . 'FROM news ' . 'ORDER BY date DESC ';
$stmt = $conn->prepare($sql);
//dayardayt
/* execute prepared statement */
$stmt->execute();
//zapros
$stmt->store_result();
// zapros
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $title, $date, $sh_content);
// kelgen maanini yigarat
// output data of each row
$i = 0;
while ($row = $stmt->fetch()) {
$newsList[$i]['id'] = $id;
$newsList[$i]['title'] = $title;
$newsList[$i]['date'] = $date;
$newsList[$i]['sh_content'] = $sh_content;
$i++;
}
}
return $newsList;
}
示例3: getNewsList
public static function getNewsList()
{
//запрос к БД
$db = Db::getConnection();
//вызываем метод с параметрами подкдючения к базе данных
$newsList = array();
//Создем пустой масив для сохранения результатов
$result = $db->query('SELECT id,title,date,short_content FROM news LIMIT 4');
//Нужний запрос к БД
if (!$result) {
die("Execute query error");
}
$i = 0;
while ($row = $result->fetch(true)) {
// $row -символизирует строку из базы даных
//В цикле мы записываем необходимые даные в масив результатов
$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;
//Возвращаем масив
}
示例4: check
public function check()
{
$username = $_POST['username'];
$password = $_POST['password'];
$conn = Db::getConnection();
$sql = "SELECT username, password, admin\n\t\t\t\tFROM users\n\t\t\t\tWHERE username = '{$username}'";
$q = $conn->prepare($sql);
$q->execute();
$users = $q->fetch(\PDO::FETCH_ASSOC);
//var_dump($users);die(' proba');
$logger = new Logger();
$error = $logger->checkCredentials($password, $users);
//$isAdmin = $logger->checkAdmin($password,$users);
//var_dump($error);die(' ajde vise!!!');
if ($error) {
//echo '<pre>'; var_dump($error);die(); echo '</pre>';
$html = new Html($this->controllerName);
$html->error = $error;
//echo '<pre>'; var_dump($html->error);die(); echo '</pre>';
$html->render('index');
} else {
$user = new User($users['username'], $users['admin']);
$user->login();
//var_dump($user);die(' jebem li ga');
header('Location: /');
}
}
示例5: Reg
public static function Reg($reg_name, $reg_surname, $reg_phone, $reg_email, $reg_location, $reg_password_hash, $reg_avatar)
{
$db = Db::getConnection();
$query = $db->prepare("INSERT INTO registration (reg_id, reg_name, reg_surname, reg_date, reg_phone, reg_email, reg_location, reg_password_hash, vk_account, reg_avatar) \n\t\t\t\t\t\t\t\tVALUES (NULL, :reg_name, :reg_surname, CURRENT_TIMESTAMP, :reg_phone, :reg_email, :reg_location, :reg_password_hash, 0, :reg_avatar);");
$query->execute(array('reg_name' => "{$reg_name}", 'reg_surname' => "{$reg_surname}", 'reg_phone' => "{$reg_phone}", 'reg_email' => "{$reg_email}", 'reg_location' => "{$reg_location}", 'reg_password_hash' => "{$reg_password_hash}", 'reg_avatar' => "{$reg_avatar}"));
return $query;
}
示例6: create
public function create()
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$conn = Db::getConnection();
$sql = "SELECT *\n\t\t\t\tFROM users";
$q = $conn->prepare($sql);
$q->execute();
$users = $q->fetchAll(\PDO::FETCH_ASSOC);
$validator = new Validator();
$error = $validator->validateRegisterForm($_POST, $users);
//echo '<pre>'; var_dump($error); echo '</pre>';die();
if ($error) {
//echo '<pre>'; var_dump($error);die(); echo '</pre>';
$html = new Html($this->controllerName);
$html->error = $error;
//echo '<pre>'; var_dump($html->error);die(); echo '</pre>';
//;kweojn'dlfv'dlfkv
$html->render('index');
} else {
$newUserSql = "INSERT INTO users\n\t\t\t(`firstname`, `lastname`, `email`, `username`, `password`, `admin`)\n\t\t\tVALUES\n\t\t\t('{$firstname}', '{$lastname}', '{$email}', '{$username}', '{$password}', '0')";
$q = $conn->prepare($newUserSql);
$q->execute();
header('Location: /login/index');
}
}
示例7: 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'];
}
示例8: GetInfo
public static function GetInfo($reg_id)
{
$db = Db::getConnection();
$query = $db->prepare("SELECT * FROM registration WHERE reg_id = :reg_id;");
$query->execute(array('reg_id' => "{$reg_id}"));
$result = $query->fetch();
return $result;
}
示例9: addUser
public static function addUser($login, $password)
{
$db = Db::getConnection();
$sql = 'INSERT INTO users (login, password) VALUES (:login, :password)';
$result = $db->prepare($sql);
$result->bindParam(':login', $login, PDO::PARAM_INT);
$result->bindParam(':password', $password, PDO::PARAM_INT);
$result->execute();
return $result->execute();
}
示例10: table
static function table($with_db_name = true)
{
$conn = Db::getConnection('streams');
$prefix = empty($conn['prefix']) ? '' : $conn['prefix'];
$table_name = $prefix . 'notification';
if (!$with_db_name) {
return $table_name;
}
$db = Db::connect('streams');
return $db->dbName() . '.' . $table_name;
}
示例11: checkEmailExists
public static function checkEmailExists($email)
{
$db = Db::getConnection();
$sql = 'SELECT COUNT(*) FROM user WHERE email = :email';
$result = $db->prepare($sql);
$result->bindParam(':email', $email, PDO::PARAM_STR);
$result->execute();
if ($result->fetchColumn()) {
return true;
}
return false;
}
示例12: amIAdmin
public static function amIAdmin($get_reg_id)
{
$db = Db::getConnection();
$query = $db->prepare("SELECT is_admin FROM registration WHERE reg_id = :reg_id;");
$query->execute(array('reg_id' => "{$get_reg_id}"));
$result = $query->fetch();
if ($result['is_admin'] == 1) {
return True;
} else {
return False;
}
}
示例13: 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;
}
示例14: getList
/**
* Return array with list of works
* @return array
*/
public static function getList()
{
$db = Db::getConnection();
$list = array();
$result = $db->query('SELECT title, link FROM base WHERE type="uslugi"');
$i = 0;
while ($row = $result->fetch()) {
$list[$i]['title'] = $row['title'];
$list[$i]['link'] = $row['link'];
$i++;
}
return $list;
}
示例15: getCategoriesList
/**
* Returns an array of categories
*/
public static function getCategoriesList()
{
$db = Db::getConnection();
$categoryList = array();
$result = $db->prepare('SELECT id, name FROM category ORDER BY sort_order ASC');
$result->execute();
$row = $result->fetchAll(PDO::FETCH_ASSOC);
for ($i = 0; $i < count($row); $i++) {
$categoryList[$i]['id'] = $row[$i]['id'];
$categoryList[$i]['name'] = $row[$i]['name'];
}
return $categoryList;
}