Advertisement
Guest User

qwewqewqe

a guest
Nov 20th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. <?php
  2. if(defined("include_banco_class") === false){
  3. define("include_banco_class", true);
  4. define("HOST", 0);
  5. define("USER", 1);
  6. define("PASS", 2);
  7. define("DB", 3);
  8. class banco{
  9. private $con = null;
  10. private $host = null;
  11. private $user = null;
  12. private $pass = null;
  13. private $db = null;
  14.  
  15. public function __construct($host = null, $user = null, $pass = null, $db = null){
  16. if($host === null or $user === null or $pass === null or $db === null){
  17. $this->host = "localhost";
  18. $this->user = "root";
  19. $this->pass = "";
  20. $this->db = "lnd";
  21. }
  22. else{
  23. $this->host = $host;
  24. $this->user = $user;
  25. $this->pass = $pass;
  26. $this->db = $db;
  27. }
  28. return true;
  29. }
  30.  
  31. public function SetVar($val, $type){
  32. switch(intval($type)){
  33. case HOST:{
  34. $this->host = $val;
  35. return true;
  36. }
  37. case USER:{
  38. $this->user = $val;
  39. return true;
  40. }
  41. case PASS:{
  42. $this->pass = $val;
  43. return true;
  44. }
  45. case DB:{
  46. $this->db = $val;
  47. return true;
  48. }
  49. default:{
  50. return false;
  51. }
  52. }
  53. return false;
  54. }
  55. public function connect(){
  56. if($this->host === null or $this->user === null or $this->pass === null or $this->db === null){
  57. return false;
  58. }
  59. if($this->con !== null){
  60. return false;
  61. }
  62. $this->con = new mysqli($this->host, $this->user, $this->pass, $this->db);
  63. if($this->con->connect_error){
  64. echo utf8_encode("Erro ao se conectar ao banco de dados:<br/>".$this->con->connect_errno."<br/>".$this->con->connect_error);
  65. $this->con = null;
  66. return false;
  67. }
  68. return true;
  69. }
  70. public function connected(){
  71. if($this->con === null || $this->con === false){
  72. return false;
  73. }
  74. return true;
  75. }
  76. public function query($query){
  77. if($this->con === null || $this->con === false){
  78. return false;
  79. }
  80. return $this->con->query($query);
  81. }
  82. public function insert_id(){
  83. if($this->con === null || $this->con === false){
  84. return 0;
  85. }
  86. return $this->con->insert_id;
  87. }
  88. public function real_escape_string($string){
  89. if($this->con === null || $this->con === false){
  90. return null;
  91. }
  92. return $this->con->real_escape_string($string);
  93. }
  94. public function affected_rows(){
  95. if($this->con === null || $this->con === false){
  96. return 0;
  97. }
  98. return $this->con->affected_rows;
  99. }
  100. public function error(){
  101. if($this->con === null || $this->con === false){
  102. return null;
  103. }
  104. return $this->con->error;
  105. }
  106. public function close(){
  107. if($this->con === null){
  108. return false;
  109. }
  110. $this->con->close();
  111. $this->con = null;
  112. return true;
  113. }
  114. public function __destruct(){
  115. $this->close();
  116. }
  117. }
  118. }
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement