Guest User

Untitled

a guest
Mar 14th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. CALL `add_full`('game 1', 2222645576, 'http://info.com/data/1234', '2018-03-01 19:01:11')
  2.  
  3. class Database
  4. {
  5. private static $user = "root";
  6. private static $pass = "test";
  7. private static $db = "db";
  8. private static $server = "localhost";
  9.  
  10. private $conn;
  11.  
  12. private static $add_full_sp = "add_full";
  13.  
  14. public function __construct()
  15. {
  16. $this->conn = new mysqli(self::$server, self::$user, self::$pass, self::$db);
  17. if ($this->conn->connect_error) {
  18. throw new Exception("Connection failed: " . $conn->connect_error);
  19. }
  20. }
  21.  
  22. public function __destruct()
  23. {
  24. $this->conn->close();
  25. }
  26.  
  27.  
  28. public function addFull($name, $size, $url, $date)
  29. {
  30. $call = "CALL `" . self::$add_full_sp . "`('" . $name . "', " . $size . ", '" . $url . "', '".$date."')";
  31.  
  32. //var_dump($call);
  33. $this->conn->query($call);
  34. }
  35. }
  36.  
  37. $db = new Database();
  38.  
  39. foreach($json as $item) {
  40. if(array_search($item, $list)) {
  41. continue;
  42. }
  43.  
  44. $bytes = round(textToSize($item->size));
  45. $date = $item->date; // it is 2018-03-01 12:12:12
  46. $db->addFull($item->name, $bytes, $item->url, $date);
  47. }
Add Comment
Please, Sign In to add comment