Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2. class DB{
  3. // conexion a la DB
  4. private $dbHost = "localhost";
  5. private $dbUsername = "root";
  6. private $dbPassword = "password";
  7. private $dbName = "croquis";
  8. private $imgTbl = 'mesas';
  9.  
  10. function __construct(){
  11. if(!isset($this->db)){
  12. // conectar a la db
  13. $conn = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
  14. if($conn->connect_error){
  15. die("Error de conexion a la DB: " . $conn->connect_error);
  16. }else{
  17. $this->db = $conn;
  18. }
  19. }
  20. }
  21.  
  22. function getRows(){
  23. $query = $this->db->query("SELECT * FROM ".$this->imgTbl." ORDER BY img_order ASC");
  24. if($query->num_rows > 0){
  25. while($row = $query->fetch_assoc()){
  26. $result[] = $row;
  27. }
  28. }else{
  29. $result = FALSE;
  30. }
  31. return $result;
  32. }
  33.  
  34. function updateOrder($id_array){
  35. $count = 1;
  36. foreach ($id_array as $id){
  37. $update = $this->db->query("UPDATE ".$this->imgTbl." SET img_order = $count WHERE id = $id");
  38. $count ++;
  39. }
  40. return TRUE;
  41. }
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement