Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2.     if(isset($_POST['send'])){
  3.         $user = new User($_POST['pass'], $_POST['name'], $_POST['sex'], $_POST['email']);
  4.         var_dump($_POST);
  5.         var_dump($user);
  6.     }
  7.  
  8.     class Controller{        
  9.  
  10.         public static function insertUser($name, $pass, $email, $sex){
  11.             $conn = new ConnectionFactory->$connection;
  12.             $q = $conn->prepare("INSERT INTO USR(USR_PASS, USR_NAME, USR_SEX, USR_EMAIL)" . "VALUES('$name', '$pass', '$email', '$sex'");
  13.             $q -> execute();
  14.             $q -> close();
  15.             //$results = $q -> fetchAll(PDO::FETCH_ASSOC);
  16.         }
  17.     }
  18.     class ConnectionFactory{
  19.         public static $connection;
  20.  
  21.         private static $dbtype = "mysql";
  22.         private static $dbname = "crud_php";
  23.         private static $host = "localhost";
  24.         private static $user = "root";
  25.         private static $pass = "";
  26.  
  27.         public function getconnection(){
  28.             if(!self::$connection){
  29.                 self::$connection = new PDO("$dbase:db_name=$dbname;host=$host", $user, $pass);
  30.             }
  31.             return self::$connection;
  32.         }
  33.  
  34.     }
  35.  
  36.     class User{
  37.         public $name;
  38.         public $pass;
  39.         public $email;
  40.         public $sex;
  41.  
  42.         public function __construct($name, $pass, $email, $sex){
  43.             $this->name = $name;
  44.             $this->setPassword($pass);
  45.             $this->email = $email;
  46.             $this->sex = $sex;
  47.             Controller::insertUser($this->name, $this->pass, $this->email, $this->sex);
  48.         }
  49.  
  50.         public function getName(){
  51.             return $this->name;
  52.         }
  53.  
  54.         public function getEmail(){
  55.             return $this->email;
  56.         }
  57.  
  58.         public function __destruct(){
  59.             echo "A classe __CLASS__ foi destruída";
  60.         }
  61.  
  62.         public function setPassword($password){
  63.             $this->pass = $password;
  64.         }
  65.         public function __toString(){
  66.             return $this->getName() . '<br/>' . $this->getEmail();
  67.  
  68.         }
  69.     }    
  70.  
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement