Advertisement
Guest User

Untitled

a guest
Oct 8th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <?
  2. /* DATABASE CONN */
  3. define('DB_SERVER', '111.111.111.111');
  4. define('DB_USERNAME', 'user');
  5. define('DB_PASSWORD', 'passs');
  6. define('DB_DATABASE', 'db');
  7. define("BASE_URL", "https://example.com/");
  8.  
  9.  
  10. @error_reporting(E_ERROR | E_WARNING | E_PARSE);
  11.  
  12.  
  13.  
  14. function connectDB()
  15. {
  16. $dbhost=DB_SERVER;
  17. $dbuser=DB_USERNAME;
  18. $dbpass=DB_PASSWORD;
  19. $dbname=DB_DATABASE;
  20. try {
  21. $dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
  22. $dbConnection->exec("set names utf8");
  23. $dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  24. $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  25. return $dbConnection;
  26. }
  27. catch (PDOException $e) {
  28. echo 'DB conn error : ' . $e->getMessage();
  29. }
  30.  
  31. }
  32.  
  33. ?>
  34.  
  35. <?php
  36.  
  37. class userClass
  38. {
  39.  
  40. public function login($Email,$pass)
  41. {
  42. try{
  43. $db = connectDB();
  44. $hash_sifre= hash('sha256', $pass);
  45. $stmt = $db->prepare("SELECT `id` FROM `member` WHERE `email`=:Email AND `pass`=:hash_pass");
  46. $stmt->bindParam("Email", $Email,PDO::PARAM_STR) ;
  47. $stmt->bindParam("hash_pass", $hash_pass,PDO::PARAM_STR) ;
  48. $stmt->execute();
  49. $count=$stmt->rowCount();
  50. $data=$stmt->fetch(PDO::FETCH_OBJ);
  51. $db = null;
  52. if($count)
  53. {
  54. $_SESSION['id']=$data->id;
  55. return true;
  56.  
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }
  63. catch(PDOException $e) {
  64. echo '{"error":{"text":'. $e->getMessage() .'}}';
  65. }
  66.  
  67. $db = null;
  68. }
  69.  
  70.  
  71.  
  72.  
  73. public function info($id)
  74. {
  75. try{
  76. $db = connectDB();
  77. $stmt = $db->prepare("SELECT `name` FROM `member` WHERE `id`=:id");
  78. $stmt->bindParam("id", $id,PDO::PARAM_INT);
  79. $stmt->execute();
  80. $data = $stmt->fetch(PDO::FETCH_OBJ);
  81. return $data;
  82. }
  83. catch(PDOException $e) {
  84. echo '{"error":{"text":'. $e->getMessage() .'}}';
  85. }
  86. }
  87.  
  88. }
  89. ?>
  90.  
  91. <?
  92. include "settings.php";
  93. include "userClass.php";
  94.  
  95. $userClass = new userClass();
  96.  
  97. .
  98. .
  99. .
  100. Many another classes here like userClass calling.
  101.  
  102. after im using ..
  103.  
  104. ?>
  105.  
  106. <?
  107.  
  108. include "header.php";
  109.  
  110.  
  111. $id = $_SESSION['id'];
  112. $memberInfo=$userClass->info($id);
  113.  
  114.  
  115. echo $memberInfo->name;
  116.  
  117. and like thats many many queries.
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement