Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. INDEX
  2. <?php
  3. require_once("user.php");
  4.  
  5. $server = "localhost";
  6. $user = "root";
  7. $pass = "";
  8. $database = "test";
  9.  
  10. $mysqli = new mysqli($server,$user,$pass,$database);
  11.  
  12.  
  13. if (mysqli_connect_errno()){
  14. echo "falha ao conectar-se ao mysql:(".$mysqli->connect_errno.") ".$mysqli-connect_error;
  15. exit;
  16. }
  17. $User = new user($mysqli);
  18.  
  19.  
  20. $User->setName("Pepe")
  21. ->setEmail("pepinho@gmail.com");
  22.  
  23.  
  24.  
  25. echo $User->insert();
  26.  
  27.  
  28.  
  29.  
  30. user.php
  31. <?php
  32.  
  33. class user
  34. {
  35. private $db;
  36. private $name;
  37. private $id;
  38. private $email;
  39.  
  40.  
  41. function __construct(Mysqli $mysqli)
  42. {
  43. $this->db = $mysqli;
  44. }
  45. public function lista()
  46. {
  47.  
  48. }
  49. public function insert()
  50. {
  51. $stmt = $this->db->stmt_init();
  52. $stmt->prepare("INSERT INTO user(name,email)VALUES(?,?)");
  53. $stmt->bind_param("s", $this->name);
  54. $stmt->execute();
  55. return $stmt->insert_id;
  56.  
  57. }
  58.  
  59.  
  60. public function update()
  61. {
  62.  
  63. }
  64. public function delete()
  65. {
  66.  
  67. }
  68.  
  69.  
  70.  
  71. //seters e geters
  72. public function getId()
  73. {
  74. return $this->id;
  75. }
  76.  
  77. public function setId($id)
  78. {
  79. $this->id = $id;
  80. return $this;
  81. }
  82.  
  83. public function getName()
  84. {
  85. return $this->name;
  86. }
  87.  
  88. public function setName($name)
  89. {
  90. $this->name = $name;
  91. return $this;
  92. }
  93.  
  94. public function getEmail()
  95. {
  96. return $this->email;
  97. }
  98.  
  99. public function setEmail($email)
  100. {
  101. $this->email = $email;
  102. return $this;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement