Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2.  
  3. class login {
  4.  
  5. private $username ;
  6. private $pass ;
  7.  
  8.  
  9. public function __construct($username , $pass ) {
  10.  
  11.  
  12. $this->connect();
  13. $this->setdata($username , $pass );
  14. $this->login($username , $pass );
  15.  
  16. }
  17.  
  18. private function connect(){
  19.  
  20. include 'database.php';
  21. new connect();
  22. }
  23.  
  24. private function setdata($username , $pass ){
  25.  
  26. $this->username = $username ;
  27. $this->pass = $pass ;
  28.  
  29. }
  30.  
  31. private function login($username , $pass ) {
  32.  
  33. global $con ;
  34.  
  35. $stmt = $con->prepare("SELECT username, password FROM user WHERE username =? AND password =? ") ;
  36.  
  37. $stmt->execute(array($username, $pass));
  38.  
  39. $get = $stmt->fetch();
  40.  
  41. $count = $stmt->rowCount();
  42.  
  43.  
  44.  
  45. if ($count > 0 ){
  46.  
  47. return TRUE;
  48. }
  49. else {
  50. throw new Exception("xxxxxxxxxx");
  51. }
  52. }
  53.  
  54. }
  55.  
  56.  
  57.  
  58. =========================================
  59.  
  60.  
  61. <?php
  62.  
  63. class connect {
  64.  
  65.  
  66. public function __construct(){
  67.  
  68.  
  69.  
  70. $dsn = 'mysql:host=localhost;dbname=ali';
  71. $user = 'root';
  72. $pass = '';
  73. $option = array(
  74. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  75. );
  76.  
  77. try {
  78. $con = new PDO($dsn, $user, $pass, $option);
  79. $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  80. echo "<br> you are connected <br>" ;
  81. return $con;
  82.  
  83. }
  84.  
  85. catch(PDOException $e) {
  86. echo 'Failed To Connect' . $e->getMessage();
  87. }
  88.  
  89. }
  90.  
  91.  
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement