Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <?php
  2. $db_host = 'localhost';
  3. $db_name = "dados";
  4. $mysql_charset = "utf8";
  5. $db_username = "root";
  6. $db_password = "";
  7.  
  8. // Initiate curl
  9. $ch = curl_init();
  10. // Disable SSL verification
  11. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  12. // Will return the response, if false it print the response
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. // Set the url
  15. curl_setopt($ch, CURLOPT_URL, "http://graph.facebook.com/?id=https://gamaiaziz.com.br");
  16. // Execute
  17. $result = curl_exec($ch);
  18. // Closing
  19. curl_close($ch);
  20.  
  21. // Will dump a beauty json :3
  22. var_dump(json_decode($result, true));
  23.  
  24. $json = json_decode($result, true);
  25.  
  26. echo " <br />Compartilhamento Atual:".$json["share"]["share_count"];
  27.  
  28. //conexão com o host
  29. try{
  30. $PDO = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset='.$mysql_charset, $db_username, $db_password);
  31. }catch(PDOException $e){
  32. echo($e->getMessage());
  33. }
  34.  
  35. //selecionar tabela
  36. $stmt = $PDO->prepare("SELECT * FROM tab_produtos WHERE cmp_codigo = 350395");
  37. $stmt->execute();
  38. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  39. ################################################################
  40.  
  41. $url = $row['url'];
  42. //header("location:$url");
  43.  
  44. // dados
  45. $shared = $row['shared'];
  46.  
  47. echo "<br ><br >Compartilhamento até o inicio: ".$shared;
  48.  
  49. $atual = $json["share"]["share_count"] - $shared;
  50. echo "<br ><br >Atual da Pagina:".$atual;
  51.  
  52. // Preços
  53.  
  54. $preco = $row['cmp_preco_de'];
  55. $precoMin = $row['promo'];
  56. $desconto = $row['desconto'];
  57.  
  58. // formula de calculo
  59.  
  60. $precoAtual = $preco - ( $desconto * $atual );
  61.  
  62.  
  63. echo "<br ><br >".$preco." -> ".$precoAtual;
  64.  
  65. if($precoAtual <= $precoMin){
  66.  
  67. // If para remover o item após ultrapassar o preço minimo
  68. //$stmt = $PDO->prepare("DELETE FROM teste WHERE id = 1");
  69. //$stmt->execute();
  70. //$row = $stmt->fetch(PDO::FETCH_ASSOC);
  71.  
  72. echo "<br>Remover</br>";
  73. }
  74. else {
  75. $stmt = $PDO->prepare("INSERT INTO tab_produtos(cmp_preco_de, cmp_preco_por) WHERE idpromo = 1 VALUES (':preco1', ':preco2');");
  76. $stmt->bindParam(':preco1', $precoAtual);
  77. $stmt->bindParam(':preco2', $precoAtual);
  78. $stmt->execute();
  79. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  80. }
  81.  
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement