当前位置: 首页>>代码示例>>PHP>>正文


PHP DBConnection::getDb方法代码示例

本文整理汇总了PHP中DBConnection::getDb方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::getDb方法的具体用法?PHP DBConnection::getDb怎么用?PHP DBConnection::getDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBConnection的用法示例。


在下文中一共展示了DBConnection::getDb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getSectors

 public static function getSectors()
 {
     $dbc = new DBConnection();
     $sectors = array();
     $selected = array();
     $query = $dbc->getDb()->prepare("SELECT * FROM sectors ORDER BY level, name");
     $query->execute();
     if ($query->rowCount() > 0) {
         $root_sectors = array();
         $parent_sectors = array();
         $res = $query->fetchAll(PDO::FETCH_ASSOC);
         foreach ($res as $row) {
             if ($row['level'] == 0) {
                 $root_sectors[$row['id']] = $row;
             } else {
                 $parent_sectors[$row['parent_id']][$row['id']] = $row;
             }
         }
         self::constructSectors($root_sectors, $parent_sectors, $sectors);
     }
     return $sectors;
 }
开发者ID:kkallasm,项目名称:Sectors,代码行数:22,代码来源:Sector.php

示例2: DBConnection

<?php

ob_start();
session_start();
require_once 'modules/DBConnection.php';
//save data
if ($_REQUEST['save']) {
    if ($_REQUEST['name'] && $_REQUEST['terms'] && $_REQUEST['sectors'] && is_array($_REQUEST['sectors'])) {
        $dbc = new DBConnection();
        $name = $_REQUEST['name'];
        //update user and data
        if (isset($_SESSION['user_id']) && intval($_SESSION['user_id'])) {
            $user_id = $_SESSION['user_id'];
            $query = $dbc->getDb()->prepare("UPDATE users SET name = :name WHERE id = :user_id");
            $query->bindValue(':name', $name);
            $query->bindValue(':user_id', $user_id);
            $query->execute();
            //delete from user_sectors and add new ones
            $query = $dbc->getDb()->prepare("DELETE FROM user_sectors WHERE user_id = :user_id");
            $query->bindValue(':user_id', $user_id);
            $query->execute();
            foreach ($_REQUEST['sectors'] as $sector_id) {
                $query = $dbc->getDb()->prepare("INSERT INTO user_sectors VALUES(:user_id, :sector_id)");
                $query->bindValue(':user_id', $user_id);
                $query->bindValue(':sector_id', $sector_id);
                $query->execute();
            }
            $_SESSION['user_name'] = $name;
            $_SESSION['sectors'] = $_REQUEST['sectors'];
        } else {
            $query = $dbc->getDb()->prepare("INSERT INTO users(name) VALUES(:name)");
开发者ID:kkallasm,项目名称:Sectors,代码行数:31,代码来源:actions.php

示例3: DBConnection

<?php

chdir('../');
require_once 'modules/DBConnection.php';
$dbc = new DBConnection();
print "***********  CREATE USERS TABLE ****************\n";
$sql = "CREATE TABLE users ( \n                id INT NOT NULL AUTO_INCREMENT,\n                name VARCHAR(255) NOT NULL,\n                PRIMARY KEY (id))";
$dbc->getDb()->exec($sql);
print "Users table created \n\n";
print "***********  CREATE SECTORS TABLE ****************\n";
$sql = "CREATE TABLE sectors ( \n                id INT NOT NULL AUTO_INCREMENT,\n                parent_id INT,\n                name VARCHAR(255) NOT NULL,\n                level INT NOT NULL,\n                PRIMARY KEY (id))";
$dbc->getDb()->exec($sql);
print "Sectors table created \n\n";
print "***********  CREATE USER_SECTORS TABLE ****************\n";
$sql = "CREATE TABLE user_sectors ( \n                user_id INT NOT NULL,\n                sector_id INT NOT NULL,\n                FOREIGN KEY (user_id) REFERENCES users(id),\n                FOREIGN KEY (sector_id) REFERENCES sectors(id))";
$dbc->getDb()->exec($sql);
print "User_sectors table created \n\n";
print "***********  INSERT DATA TO SECTOR TABLE ****************\n\n";
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTMLFile('scripts/index.html');
$parent_id = null;
$prev_lvl = 0;
$parents = array();
foreach ($doc->getElementsByTagName('option') as $opt) {
    $id = intval($opt->getAttribute('value'));
    $value = mb_convert_encoding($opt->nodeValue, 'HTML-ENTITIES', 'UTF-8');
    $level = intval(substr_count($value, '&nbsp;') / 4);
    $name = trim(str_replace('&nbsp;', '', $value));
    if ($level == 0) {
        $parent_id = $id;
开发者ID:kkallasm,项目名称:Sectors,代码行数:31,代码来源:init.php


注:本文中的DBConnection::getDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。