Advertisement
hujuice

DB rude example

Feb 10th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Doc Comment Here
  4.  */
  5. class User
  6. {
  7.     /**
  8.      * The database
  9.      *
  10.      * @var \PDO
  11.      */
  12.     protected $_db;
  13.    
  14.     /**
  15.      * Create the database object
  16.      *
  17.      * @param array $config
  18.      */
  19.     public function __construct($config)
  20.     {
  21.         $dsn = 'mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'];
  22.         $this->_db = new \PDO($dsn, $config['user'], $config['pass']);
  23.     }
  24.    
  25.     /**
  26.      * Perform the login
  27.      *
  28.      * @param string $name              The user name
  29.      * @param string $pass              The user password
  30.      * @return
  31.      */
  32.     public function login($name, $pass)
  33.     {
  34.         if (!empty($name) && !empty($pass) ){
  35.             $st = $this->db->prepare ("select * from users where where name=? and pass =? ");
  36.             $st->bindValue(1, $name);
  37.             $st->bindValue(2, $pass);
  38.             $st->execute;
  39.             if ($st->rowCount() == 1) {
  40.                 echo "Accesso Verificato";
  41.             } else {
  42.                 echo "utente non riconosciuto";
  43.             }
  44.         } else {
  45.             echo"Inserire Username e Password";
  46.         }
  47.     }
  48. }
  49.  
  50. $config = parse_ini_file('/path/to/config.ini');
  51. $user = new User($config);
  52. $user->login($name, $pass);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement