Exemplo n.º 1
0
 /**
  * Static method get
  *
  * @param  array $group
  * @return \helpers\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, 'port' => DB_PORT) : $group;
     // Group information
     $type = $group['type'];
     $host = $group['host'];
     $name = $group['name'];
     $user = $group['user'];
     $pass = $group['pass'];
     $port = $group['port'];
     // ID for database based on the group information
     $id = "{$type}.{$host}.{$port}.{$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};port={$port};dbname={$name};charset=utf8", $user, $pass);
         $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         // 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();
     }
 }
 /**
  * Implements add student
  * @access public
  * @param array $studentsData Contains students data
  * @return bool|string Notice of the result
  */
 public function addStudent($studentsData)
 {
     $warningMessage = "";
     if (isset($studentsData['save'])) {
         array_shift($studentsData);
         array_pop($studentsData);
         $this->db = DataBase::getInstance();
         $studentsData = $this->sanitizeMySQL($this->db->getDBConnection(), $studentsData);
         $studentValues = $this->getValues($studentsData);
         array_unshift($studentValues, 'NULL');
         $this->db->insert($this->db_config['tb_university'], $studentValues);
         $warningMessage = 'Данные успешно сохранены!';
     }
     return $warningMessage;
 }
 public function addUser($userData = array())
 {
     $warningMessage = $this->checkAll($userData);
     if ($warningMessage === true) {
         $this->db = \core\DataBase::getInstance();
         $userData = $this->sanitizeMySQL($this->db->getDBConnection(), $userData);
         $userValues = $this->getUserValues($userData);
         $result = $this->db->insert($this->db_config['tb_users'], $userValues);
         if ($result) {
             $warningMessage = 'Учетная запись создана успешно!';
         } else {
             $warningMessage = 'Учетная запись с таким логином уже существует!!!';
         }
     }
     return $warningMessage;
 }
Exemplo n.º 4
0
 public function loginUser($userAuth = array())
 {
     if ($this->checkFields($userAuth)) {
         $this->db = \core\DataBase::getInstance();
         $userAuth = $this->sanitizeMySQL($this->db->getDBConnection(), $userAuth);
         $hashPass = $this->getPasswordHash($userAuth['password']);
         $result = $this->db->selectRow('*', $this->db_config['tb_users'], array('userName', 'password'), array($userAuth['userName'], $hashPass));
         if ($result) {
             $_SESSION['user'] = array_shift($result);
             $warningMessage = null;
         } else {
             $warningMessage = "Вы ввели неправильное имя пользователя или пароль!!!";
         }
     } else {
         $warningMessage = "Заполните все поля!!!";
     }
     return $warningMessage;
 }
Exemplo n.º 5
0
 public function addStudent($studentsData)
 {
     if (isset($_POST['save'])) {
         $warningMessage = $this->checkFields($studentsData);
         if ($warningMessage === true) {
             array_pop($studentsData);
             $this->db = \core\DataBase::getInstance();
             $studentsData = $this->sanitizeMySQL($this->db->getDBConnection(), $studentsData);
             $studentValues = $this->getValues($studentsData);
             array_unshift($studentValues, 'NULL');
             $this->db->insert($this->db_config['tb_university'], $studentValues);
             $warningMessage = 'Данные успешно сохранены!';
         } else {
             $warningMessage = 'Заполнените все поля!!!';
         }
     } else {
         $warningMessage = 'Введите данные студента!!!';
     }
     return $warningMessage;
 }
Exemplo n.º 6
0
 /**
  * create a new instance of the database helper
  */
 public function __construct()
 {
     //connect to PDO here.
     $this->db = DataBase::get();
 }
Exemplo n.º 7
0
 public function __construct()
 {
     $this->db = DataBase::get();
 }