Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2. namespace App\Controller;
  3. use PDO;
  4.  
  5. class dbConnecterController {
  6.     public function __construct(){
  7.     }
  8.  
  9.     public  function validate(){
  10.  
  11.         $username = $_POST['username'];
  12.         $password = $_POST['password'];
  13.  
  14.         $host = "localhost";
  15.         $user = "root";
  16.         $pass = "";
  17.         $dbname = "MyGalleryDb";
  18.  
  19.  
  20.         // Handle a bit of connection errors
  21.         try {
  22.             // Connect to server via PHP Data Object
  23.             $dbconnection = new PDO('mysql:host='.$host.';dbname=' . $dbname, $user, $pass);
  24.  
  25.  
  26.  
  27.         } catch (PDOException $e) {
  28.             echo htmlentities($e);
  29.             die();
  30.         }
  31.  
  32.  
  33.         $result = $dbconnection->query("SELECT * FROM users WHERE username= $username && password= $password");
  34.         $result->setFetchMode(PDO::FETCH_ASSOC);
  35.         $row = $result->fetch();
  36.         echo $row[0];
  37.        
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement