You are here:  » Not inserting into SQL DB

Support Forum



Not inserting into SQL DB

Submitted by globologic on Sat, 2016-05-21 04:32 in

Hi David,

I ran the demo for this XML url: {link saved} and using the results I've created the following SQL PHP page but when I run it, it doesn't insert any data?

Could this be due to & characters in fields?

<?php
require("MagicParser.php");
mysql_connect("xxxx","xxx","xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
$counter 0;
function 
myRecordHandler($whill)
{
global 
$counter;
global 
$sql;
$counter++;
$sql "INSERT INTO xxxxx SET
leagueid='"
.mysql_real_escape_string($whill["LEAGUE-IDLEAGUE"])."',
sportid='"
.mysql_real_escape_string($whill["LEAGUE-IDSPORT"])."',
description='"
.mysql_real_escape_string($whill["LEAGUE-DESCRIPTION"])."',
vtm='"
.mysql_real_escape_string($whill["BANNER-VTM"])."',
gamedesc='"
.mysql_real_escape_string($whill["GAME-GMDT"])."',
gamedate='"
.mysql_real_escape_string($whill["GAME-GMTM"])."',
gametime='"
.mysql_real_escape_string($whill["GAME-VTM"])."',
gamevisitor='"
.mysql_real_escape_string($whill["GAME-HTM"])."',
gamehome='"
.mysql_real_escape_string($whill["GAME/LINE-VSPRDH"])."',
visitorodds='"
.mysql_real_escape_string($whill["GAME/LINE-HSPRDH"])."',
homeodds='"
.mysql_real_escape_string($whill["GAME@1-GMDT"])."',
game1date='"
.mysql_real_escape_string($whill["GAME@1-GMTM"])."',
game1time='"
.mysql_real_escape_string($whill["GAME@1-VTM"])."',
game1visitor='"
.mysql_real_escape_string($whill["GAME@1-HTM"])."',
game1home='"
.mysql_real_escape_string($whill["GAME/LINE@1-VSPRDH"])."',
game1visitorodds='"
.mysql_real_escape_string($whill["GAME/LINE@1-HSPRDH"])."',
game1homeodds='"
.mysql_real_escape_string($whill["GAME/LINE@1-HSPRDH"])."')";
mysql_query($sql);
}
mysql_query("TRUNCATE TABLE xxxxx");
MagicParser_parse("{link saved}","myRecordHandler","xml|DATA/LEAGUES/LEAGUE/");
print 
"<p>Processed ".$counter." records.</p>";
print 
"<p>Last SQL statement was: ".$sql."</p>";
print 
mysql_error();
echo 
"Data Inserted!";
exit()
?>

Submitted by support on Sat, 2016-05-21 10:02

Hi,

Structure looks OK - how many records does your script indicated were processed at the end?

I presume there is no output from mysql_error()?

Cheers,
David
--
MagicParser.com

Submitted by globologic on Mon, 2016-05-23 04:38

yeah says 0 records inserted

Submitted by support on Mon, 2016-05-23 08:13

Hi,

That could imply that the database connection is being lost for some reason - what I would suggest is passing the $link value for each of the calls to the MySQL functions - have a go with the following;

<?php
require("MagicParser.php");
$link mysql_connect("xxxxx","xxxxx","xxxxx") or die(mysql_error());
mysql_select_db("xxxxx",$link) or die(mysql_error($link));
$counter 0;
function 
myRecordHandler($whill)
{
global 
$counter;
global 
$link;
$counter++;
$sql "INSERT INTO xxxxx SET
leagueid='"
.mysql_real_escape_string($whill["LEAGUE-IDLEAGUE"],$link)."',
sportid='"
.mysql_real_escape_string($whill["LEAGUE-IDSPORT"],$link)."',
description='"
.mysql_real_escape_string($whill["LEAGUE-DESCRIPTION"],$link)."',
vtm='"
.mysql_real_escape_string($whill["BANNER-VTM"],$link)."',
gamedesc='"
.mysql_real_escape_string($whill["GAME-GMDT"],$link)."',
gamedate='"
.mysql_real_escape_string($whill["GAME-GMTM"],$link)."',
gametime='"
.mysql_real_escape_string($whill["GAME-VTM"],$link)."',
gamevisitor='"
.mysql_real_escape_string($whill["GAME-HTM"],$link)."',
gamehome='"
.mysql_real_escape_string($whill["GAME/LINE-VSPRDH"],$link)."',
visitorodds='"
.mysql_real_escape_string($whill["GAME/LINE-HSPRDH"],$link)."',
homeodds='"
.mysql_real_escape_string($whill["GAME@1-GMDT"],$link)."',
game1date='"
.mysql_real_escape_string($whill["GAME@1-GMTM"],$link)."',
game1time='"
.mysql_real_escape_string($whill["GAME@1-VTM"],$link)."',
game1visitor='"
.mysql_real_escape_string($whill["GAME@1-HTM"],$link)."',
game1home='"
.mysql_real_escape_string($whill["GAME/LINE@1-VSPRDH"],$link)."',
game1visitorodds='"
.mysql_real_escape_string($whill["GAME/LINE@1-HSPRDH"],$link)."',
game1homeodds='"
.mysql_real_escape_string($whill["GAME/LINE@1-HSPRDH"],$link)."')";
mysql_query($sql,$link) or die(mysql_error($link));
}
mysql_query("TRUNCATE TABLE xxxxx");
MagicParser_parse("xxxxx","myRecordHandler","xml|DATA/LEAGUES/LEAGUE/");
print 
"<p>Processed ".$counter." records.</p>";
print 
"<p>Last SQL statement was: ".$sql."</p>";
print 
mysql_error();
echo 
"Data Inserted!";
exit()
?>

If still no joy, if you could submit the feed as a Get It Coded request for Insert into a MySQL database i'll forward my standard MySQL example customised for this feed to you...

Cheers,
David
--
MagicParser.com

Submitted by globologic on Mon, 2016-05-23 13:24

Thanks Dave,

That didn't work so I have lodged it as a "Get it Coded" for SQL

Thanks

Jason