Пример #1
0
 public function login($username, $password)
 {
     $db = \Lib\Database::get_instance();
     $dbconn = $db->get_db();
     $statement = $dbconn->prepare("SELECT id, role_id FROM users WHERE username = ? AND password = ? LIMIT 1");
     $statement->bind_param('ss', $username, $password);
     $statement->execute();
     $statement->bind_result($id, $role_id);
     $statement->fetch();
     if ($id && $role_id) {
         $_SESSION['username'] = $username;
         $_SESSION['user_id'] = $id;
         $_SESSION['role_id'] = $role_id;
         return true;
     }
     //
     //
     //		$result_set = $statement->store_result();
     //
     //		if ( $row = $result_set->fetch() ) {
     //			$_SESSION['username'] = $username;
     //			$_SESSION['user_id'] = $row['id'];
     //            $_SESSION['role_id'] = $row['role_id'];
     //			return true;
     //		}
     return false;
 }
Пример #2
0
 public static function create($username, $total)
 {
     $sql = 'INSERT INTO orders ' . '(username, total) ' . 'VALUES (:username, :total)';
     $params = array('username' => $username, 'total' => $total);
     $id = Database::update($sql, $params);
     return new Order($username, $total, $id, Database::now());
 }
Пример #3
0
 public function __construct($data)
 {
     if (isset($data)) {
         $this->_data = $data;
     }
     $this->_db = Database::getInstance(Config::get('mysql/host'), Config::get('mysql/db'), Config::get('mysql/user'), Config::get('mysql/pass'));
 }
Пример #4
0
 /**
  * database helper ına nesneyi init et
  */
 public function __construct()
 {
     // PDO bağlantısı yapılır
     $this->_db = \Lib\Database::get();
     if (MEMCACHED_STATUS) {
         $this->memcache_connnect();
     }
 }
Пример #5
0
 public function __construct($arg = array())
 {
     $arg = array('limit' => 0);
     if (!isset($arg['table'])) {
         die('Table not defined');
     }
     extract($arg);
     $this->table = $table;
     $this->limit = $limit;
     $db_object = \Lib\Database::get_instance();
     $this->db = $db_object::get_db();
 }
 public function __construct($args = array())
 {
     $args = array_merge(array('where' => '', 'columns' => '*', 'limit' => 0), $args);
     if (!isset($args['table'])) {
         die('Table not defined. Please define a model table.');
     }
     extract($args);
     $this->table = $table;
     $this->where = $where;
     $this->columns = $columns;
     $this->limit = $limit;
     $db_object = \Lib\Database::get_instance();
     $this->dbconn = $db_object::get_db();
 }
Пример #7
0
 public function login($username, $password)
 {
     $db_object = \Lib\Database::get_instance();
     $db = $db_object->get_db();
     $statement = $db->prepare("SELECT id FROM users WHERE username = ? AND password = MD5 ( ? ) LIMIT 1");
     $statement->bind_param('ss', $username, $password);
     $statement->execute();
     $result_set = $statement->get_result();
     if ($row = $result_set->fetch_assoc()) {
         $_SESSION['username'] = $row['username'];
         $_SESSION['user_id'] = $row['id'];
         return true;
     }
     return false;
 }
Пример #8
0
 /**
  * Static method get
  *
  * @param array $group            
  * @return \lib\database
  */
 public static function get($group = false)
 {
     // Determining if exists or it's not empty, then use default group defined in config
     $group = !$group ? array('type' => DB_TYPE, 'host' => DB_HOST, 'name' => DB_NAME, 'user' => DB_USER, 'pass' => DB_PASS) : $group;
     // Group information
     $type = $group['type'];
     $host = $group['host'];
     $name = $group['name'];
     $user = $group['user'];
     $pass = $group['pass'];
     // ID for database based on the group information
     $id = "{$type}.{$host}.{$name}.{$user}.{$pass}";
     // Checking if the same
     if (isset(self::$instances[$id])) {
         return self::$instances[$id];
     }
     try {
         // I've run into problem where
         // SET NAMES "UTF8" not working on some hostings.
         // Specifiying charset in DSN fixes the charset problem perfectly!
         $instance = new Database("{$type}:host={$host};dbname={$name};charset=UTF8", $user, $pass, array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
         $instance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8');
         // new -> stnc
         $instance->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
         $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $instance->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
         /*
          * benim eski mvc den
          * self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          * self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
          */
         // Setting Database into $instances to avoid duplication
         self::$instances[$id] = $instance;
         return $instance;
     } catch (PDOException $e) {
         // in the event of an error record the error to errorlog.html
         Logger::newMessage($e);
         logger::customErrorMsg();
     }
 }
Пример #9
0
 function __construct()
 {
     $this->database = Database::getInstance();
 }
Пример #10
0
<?php

header('Content-Type: text/html; charset=utf-8');
// Db
include 'config/db.php';
include_once 'root.php';
include_once 'lib/database.php';
include_once 'lib/auth.php';
include_once 'controllers/master_controller.php';
include_once 'controllers/topics.php';
include_once 'models/master.php';
include_once 'models/category.php';
include_once 'models/topic.php';
$db = \Lib\Database::get_instance()->get_db();
$auth = \Lib\Auth::get_instance();
$topic_controller = new \Controllers\Topic_Controller();
$category_model = new \Models\Category_Model();
$topics_model = new \Models\Topic_Model();
$message = '';
$categories = $category_model->find(array('columns' => 'name'));
if (isset($_POST['submit'])) {
    $message = $topic_controller->add($categories);
}
$title = 'Forum';
$template_file = 'views/addTopic.php';
include 'views/layouts/default.php';
Пример #11
0
 public function __construct()
 {
     $this->_db = Database::getInstance(Config::get('mysql/host'), Config::get('mysql/db'), Config::get('mysql/user'), Config::get('mysql/pass'));
     $this->_IoC = new IoC();
 }
Пример #12
0
 */
define('DX_ROOT_DIR', dirname(__FILE__) . '/');
define('DX_ROOT_PATH', basename(dirname(__FILE__)) . '/');
$request = $_SERVER['REQUEST_URI'];
$request_home = '/' . DX_ROOT_PATH;
$controller = 'master';
$methods = 'index';
$param = array();
include_once './config/db.php';
include_once './lib/database.php';
include_once 'controllers\\master.php';
if (!empty($request)) {
    if (0 === strpos($request, $request_home)) {
        $request = substr($request, strlen($request_home));
        $components = explode('/', $request, 3);
        if (1 < count($components)) {
            list($controller, $methods) = $components;
            if (isset($components[2])) {
                $param = $components[2];
            }
            include_once 'controllers/' . $controller . '.php';
        }
    }
}
$controller_class = '\\Controllers\\' . ucfirst($controller) . '_Controller';
$instance = new $controller_class();
if (method_exists($instance, $methods)) {
    call_user_func_array(array($instance, $methods), array($param));
}
$db_object = \Lib\Database::get_instance();
$db_conn = $db_object::get_db();
Пример #13
0
 public function __construct()
 {
     $this->db = \lib\Database::getInstance();
 }
Пример #14
0
<?php

error_reporting(E_ALL);
require_once __DIR__ . '/../private/config.php';
require_once __DIR__ . '/../private/vendor/Slim/Slim.php';
require_once __DIR__ . '/../private/lib/bootstrap.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim($config['website']['slim']);
\lib\Database::config($config['database']);
unset($config['database']);
\lib\MVC::config($config['website']);
\lib\MVC::registerAutoloader();
\lib\MVC::registerRouters();
$app->run();
Пример #15
0
 public static function create($username, $password, $address)
 {
     if (static::exist($username)) {
         throw new \Lib\Exceptions\DuplicateException();
     }
     $salt = Security::generate_salt();
     $hashed_password = self::generate_hash($password, $salt);
     $sql = 'INSERT INTO users ' . '(username, password, salt, address) ' . 'VALUES(:username, :password, :salt, :address)';
     $params = array('username' => $username, 'password' => $hashed_password, 'salt' => $salt, 'address' => $address);
     Database::update($sql, $params);
     return new User($username, $address);
 }
Пример #16
0
 public static function decrease_quantity($id, $quantity)
 {
     $sql = 'UPDATE products SET quantity=quantity - :quantity WHERE id=:id';
     $params = array('id' => $id, 'quantity' => $quantity);
     return Database::update($sql, $params);
 }