Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. $user = 'root';//Seu usuário do banco de dados
  4. $pass = '???';//Seu senha de conexão.
  5. $conn = null;
  6.  
  7. try {
  8.  
  9. $conn = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
  10.  
  11. } catch (PDOException $e) {
  12.  
  13. echo "Error: " . $e->getMessage();
  14. die();
  15.  
  16. }
  17.  
  18. <?php
  19.  
  20. require_once 'conexao.php';
  21.  
  22. $destUrl = 'http://steamcommunity.com/profiles/' . $steamid . '/inventory/json/730/2/';
  23.  
  24. $data = file_get_contents($destUrl, false);
  25. $data = json_decode($data, true);
  26. $data1= array_keys($data['rgDescriptions']);
  27. $data2= $data['rgDescriptions'];
  28.  
  29. $conn->beginTransaction();
  30.  
  31. //Query de inserção
  32. $sql = 'INSERT INTO sua_tabela (id, name, market_hash_name, market_name)
  33. VALUES (?, ?, ?, ?)';
  34.  
  35. $sth = $conn->prepare($sql);
  36.  
  37. for($i = 0; $i < count($data1); ++$i) {
  38.  
  39. $sth->execute(array(
  40. $data1[$i],
  41. $data2[$data1[$i]]['name'],
  42. $data2[$data1[$i]]['market_hash_name'],
  43. $data2[$data1[$i]]['market_name'];
  44. ));
  45.  
  46. }
  47.  
  48. $conn->commit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement