Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <?php
  2. if(!defined('TASK')){
  3. die();
  4. }
  5. class Database{
  6.  
  7. public $isConnect;
  8. protected $datab;
  9. private $dbHost ='localhost';
  10. private $dbPort ='3306';
  11. private $dbUser = 'root';
  12. private $dbPass = '';
  13. private $dbName = 'tasks';
  14.  
  15. public function __construct(){
  16. $this->isConnect = true;
  17. try {
  18. $this->datab = new PDO("mysql:host={$this->dbHost};port={$this->dbPort};dbname={$this->dbName};charset=utf8",$this->dbUser,$this->dbPass, $opitons = null);
  19. $this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  20. $this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  21. } catch (PDOException $e) {
  22. //throw new PDOException($e->getMessages());
  23. echo '<p> Не получилось подключиться к базе данных!</p>';
  24. die();
  25. }
  26. }
  27.  
  28. public function getRow($query, $params = []){
  29. try {
  30. $stmt = $this->datab->prepare($query);
  31. $stmt -> execute($params);
  32. return $stmt->fetch();
  33. } catch (PDOException $e) {
  34. //throw new PDOException($e->getMessages());
  35. return false;
  36. }
  37. }
  38. public function getRows($query, $params = []){
  39. try {
  40. $stmt = $this->datab->prepare($query);
  41. $stmt -> execute($params);
  42. return $stmt->fetchAll();
  43. } catch (PDOException $e) {
  44. //throw new PDOException($e->getMessages());
  45. return false;
  46. }
  47. }
  48. public function insertRow($query, $params = []){
  49. try {
  50. $stmt = $this->datab->prepare($query);
  51. $stmt -> execute($params);
  52. return true;
  53. } catch (PDOException $e) {
  54. ///throw new Exception($e->getMessages());
  55. return false;
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement