I’m trying to run a script I found in an amazing blog about sports. The instructions were
“Open the php file in a text editor, enter your MySQL connection parameters, and the desired span of years for which to get data. Uncomment the lines that create the table structure.”
I keep getting “#! /usr/bin/php Could not execute query: Table ‘nba.covers’ doesn’t exist”
Can someone please tell me what to ‘uncomment’?!? Thank you.
#! /usr/bin/php
<?php //$file="Covers.sql"; $host="localhost"; $user="root"; $pass="pass"; //exec("mysql -u ".$user." -p".$pass." -h ".$host." < ".$file); $con=mysql_connect($host,$user,$pass) or die ("Could not connect: " . mysql_error()); $htmldoc = new DOMDocument(); $url = file_get_contents('http://www.covers.com/pageLoader/pageLoader.aspx?page=/data/nba/teams/teams.html'); @$htmldoc->loadHTML($url); $doc = $htmldoc->documentElement; $teams=array(); $table=$doc->getElementsbyTagName("td"); foreach ($table as $t) { if ($t->getAttribute("class") != "datacell") continue; foreach ($table as $t) { $ahref=$t->getElementsbyTagName("a"); foreach ($ahref as $a) { $teams[$a->textContent]['Link']=substr($a->getAttribute("href"),-15); } } } unset($teams['Login']); unset($teams['Register']); unset($teams['Help']); $startyr = 1990; $endyr = 2011; $pattern = '/[^-\.0-9]*/'; for ($i = $startyr; $i<=$endyr; $i++) { $yr_url = (string)$i."-".(string)($i+1); foreach ($teams as $team=>$value) { $full_url = "http://www.covers.com/pageLoader/pageLoader.aspx?page=/data/nba/teams/pastresults/".$yr_url."/".$teams[$team]['Link']; $contents = file_get_contents($full_url); $htmldoc = new DOMDocument(); @$htmldoc->loadHTML($contents); $doc = $htmldoc->documentElement; $trs = $doc->getElementsbyTagName('tr'); foreach ($trs as $tr) { if ($tr->getAttribute('class')!="datarow") continue; $tds=$tr->getElementsbyTagName('td'); /*$teams[$team]['Date']=mysql_real_escape_string(trim(str_replace("/","",$tds->item(0)->textContent))); $teams[$team]['Home']=(strpos($tds->item(1)->textContent,"@")==0) ? 1 : 0); $teams[$team]['Vs']=mysql_real_escape_string(trim(str_replace("@","",$tds->item(1)->textContent))); $teams[$team]['Score']=mysql_real_escape_string(trim(preg_replace($pattern,'',$tds->item(2)->textContent))); $teams[$team]['Type']=mysql_real_escape_string(trim($tds->item(3)->textContent)); $teams[$team]['Line']=mysql_real_escape_string(trim(preg_replace($pattern,'',$tds->item(4)->textContent))); $teams[$team]['OU']=mysql_real_escape_string(trim(preg_replace($pattern,'',$tds->item(5)->textContent))); */ $date=mysql_real_escape_string(trim(str_replace("/","",$tds->item(0)->textContent))); $home=(strpos($tds->item(1)->textContent,"@")==0) ? 1 : 0; $vs=mysql_real_escape_string(trim(str_replace("@","",$tds->item(1)->textContent))); $line=mysql_real_escape_string(trim(preg_replace($pattern,'',$tds->item(4)->textContent))); $score=mysql_real_escape_string(trim(preg_replace($pattern,'',$tds->item(2)->textContent))); $type=mysql_real_escape_string(trim($tds->item(3)->textContent)); $ou=mysql_real_escape_string(trim(preg_replace($pattern,'',$tds->item(5)->textContent))); $f=strpos($score,'-'); if ($home == 1) { $h=$team; $away=$vs; $ubername=$date.substr($team,0,3).substr($vs,0,3); $hmscore=substr($score,0,$f); $awscore=substr($score,-(strlen($score)-$f-1)); } else { $h=$vs; $away=$team; $ubername=$date.substr($vs,0,3).substr($team,0,3); $line*=-1; $awscore=substr($score,0,$f); $hmscore=substr($score,-(strlen($score)-$f-1)); } $query = "INSERT IGNORE INTO NBA.Covers (DATE, GmNAME, HOME, AWAY, SCORE, TYPE, LINE, OU, HmScore, AwScore) VALUES ('$date','$ubername','$h','$away','$score','$type','$line','$ou','$hmscore','$awscore')"; mysql_query($query,$con) or die ("Could not execute query: " . mysql_error()); } //echo json_encode(array($team=>$teams[$team])); } } mysql_close($con); ?>PS. The code was written by http://sportsobjective.com/wordpress/