Advertisement
Guest User

Untitled

a guest
Apr 27th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------ mysql_connect.php -------------
  2. <?php
  3. function ConectToDB() {
  4.     $MyConnection = mysql_connect(server, user, password);
  5.     mysql_select_db(database);
  6.     return $MyConnection;
  7. }
  8. ?>
  9. ------------ mysql_connect.php -------------
  10.  
  11. ------------ update_streams.php ------------
  12. <?php
  13. require_once('mysql_connect.php');
  14. ConectToDB();
  15. $now = time();
  16. mysql_query("update site_tasks_helper set streams_last_verified='$now'");
  17. $query = mysql_query("select * from streams");
  18. $aux = 0;
  19. while ($aux < mysql_num_rows($query)) {
  20.     $rs = mysql_fetch_array($query);
  21.     $id = $rs["id_stream"];
  22.     $url = $rs["url"];
  23.     $site = $rs["site"];
  24.  
  25.     switch ($site) {
  26.         case "twitch":
  27.             $url = "http://api.justin.tv/api/stream/list.xml?channel=$url";
  28.             $xml = simplexml_load_file($url);
  29.             $title = $xml->stream->title;
  30.             $meta_game = $xml->stream->meta_game;
  31.             $channel_count = $xml->stream->channel_count;
  32.             if ($channel_count < 1) {
  33.                 mysql_query("update streams set title='', game='', viewers=0, online=0 where id_stream=$id");
  34.             } else {
  35.                 mysql_query("update streams set title='$title', game='$meta_game', viewers=$channel_count, online=1 where id_stream=$id");
  36.             }
  37.             break;
  38.     }
  39.     $aux++;
  40. }
  41.  
  42. mysql_close();
  43. ?>
  44. ------------ update_streams.php ------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement