Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INDEX
- <?php
- require_once("user.php");
- $server = "localhost";
- $user = "root";
- $pass = "";
- $database = "test";
- $mysqli = new mysqli($server,$user,$pass,$database);
- if (mysqli_connect_errno()){
- echo "falha ao conectar-se ao mysql:(".$mysqli->connect_errno.") ".$mysqli-connect_error;
- exit;
- }
- $User = new user($mysqli);
- $User->setName("Pepe")
- ->setEmail("pepinho@gmail.com");
- echo $User->insert();
- user.php
- <?php
- class user
- {
- private $db;
- private $name;
- private $id;
- private $email;
- function __construct(Mysqli $mysqli)
- {
- $this->db = $mysqli;
- }
- public function lista()
- {
- }
- public function insert()
- {
- $stmt = $this->db->stmt_init();
- $stmt->prepare("INSERT INTO user(name,email)VALUES(?,?)");
- $stmt->bind_param("s", $this->name);
- $stmt->execute();
- return $stmt->insert_id;
- }
- public function update()
- {
- }
- public function delete()
- {
- }
- //seters e geters
- public function getId()
- {
- return $this->id;
- }
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
- public function getName()
- {
- return $this->name;
- }
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- public function getEmail()
- {
- return $this->email;
- }
- public function setEmail($email)
- {
- $this->email = $email;
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement