Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Created by PhpStorm.
  5. * User: evtns
  6. * Date: 08/06/2016
  7. * Time: 17:55
  8. */
  9. class Database
  10. {
  11. private $db_ip = '127.0.0.1';
  12. private $db_user = 'root';
  13. private $db_pass = 'aaxd31mubr';
  14. private $db_select = 'sistema';
  15.  
  16. public function connet(){
  17. $dbc = mysqli_connect($this->db_ip,$this->db_user,$this->db_pass) or die("falha ao conectar");
  18.  
  19. if(mysqli_select_db($dbc, $this->db_select ))
  20. {
  21. echo 'DB selecionado com sucesso <br />';
  22. return $dbc;
  23. }
  24. else{
  25. echo 'falhou';
  26. return false;
  27. }
  28. }
  29.  
  30. public function __construct()
  31. {
  32.  
  33. }
  34.  
  35. public function select($cols='*',$tables ,$where=null, $value=null, $order=null)
  36. {
  37. $query = "SELECT $cols ";
  38. $query .="FROM $tables ";
  39.  
  40. if(isset($where) and isset($value))
  41. {
  42. $query .="WHERE $where='$value'";
  43. echo 'teste 1 ok';
  44. }
  45.  
  46. if(isset($order))
  47. {
  48. $query .="ORDER BY $order";
  49. }
  50.  
  51. if($result_query = mysqli_query($this->connet(), $query)){
  52. return $result_query;
  53.  
  54. }
  55. echo 'Falha ao executar querry da função select.';
  56. return false;
  57. }
  58.  
  59. public function insert($table,$val,$val1,$val2,$val3,$val4,$val5){
  60. switch ($table){
  61. case 'tbl_clientes':{
  62. $values = "INSERT INTO $table";
  63. $values .=" VALUES ('$val'";
  64. $values .=",'$val1'";
  65. $values .=",'$val2'";
  66. $values .=",'$val3'";
  67. $values .=",'$val4'";
  68. $values .=",$val5)";
  69.  
  70. $function = mysqli_query($this->connet(), $values) or die("Falha ao adicionar cliente!");
  71.  
  72. if($function){
  73. echo "Cliente $val1 adicionado com sucesso!";
  74. }
  75. else
  76. {
  77. echo "Falhou ao adicionar um cliente";
  78. }
  79. }
  80. }
  81. }
  82. public function update($table,$where,$where_v,$val1=null,$val2=null,$val3=null,$val4=null,$val5=null){
  83. switch($table){
  84. case 'tbl_clientes':
  85. $values ="UPDATE `$table` SET ";
  86. if(!empty($val1)){
  87. $values .="nome='$val1' ";
  88. if(!empty($val2)){
  89. $values .= ',';
  90. }
  91. }
  92. if(!empty($val2)){
  93. $values .="endereco='$val2' ";
  94. if(!empty($val3)){
  95. $values .= ',';
  96. }
  97. }
  98. if(!empty($val3)){
  99. $values .="telefone='$val3' ";
  100. if(!empty($val4)){
  101. $values .= ',';
  102. }
  103. }
  104. if(!empty($val4)){
  105. $values .="cidade='$val4' ";
  106. if(!empty($val5)){
  107. $values .= ',';
  108. }
  109. }
  110. if(!empty($val5)){
  111. $values .="num=$val5 ";
  112. }
  113. $values .="WHERE $where='$where_v'";
  114.  
  115. echo $values;
  116.  
  117. $result = mysqli_query($this->connet(), $values) or die("Falha ao atualizar cliente");
  118. }
  119. }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement