Thursday, 15 August 2013

PHP Script which parses all files in a directory to MySQL Database doing nothing

PHP Script which parses all files in a directory to MySQL Database doing
nothing

I have a scheduled task that uses wget to download xml updates from an API
to a directory.
If I manually run this in MySQL Workbench, it parses the xml file to the
database properly:
LOAD XML LOCAL INFILE 'C:\\WGET\\GetGame.php@id=773'
REPLACE
INTO TABLE test.games (id, GameTitle, Platform, ReleaseDate, Developer,
PlatformId);
I'm trying to automate this process, as the directory will constantly
receive new files to be parsed. I've created a .php script that should
check the folder for files and run the SQL query on anything in the
folder. (The folder cleans itself out on the hour.)
Running this seems to do nothing. I can confirm that it's logging into the
DB, it just seems to stop at the mysql query. (PHP is not my thing, yet,
so the issue will probably be a silly syntax error.)
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
$files = glob('GetGame.*');
foreach($files as $file){
mysql_query("LOAD XML LOCAL INFILE '".$file." REPLACE INTO TABLE
test.games (id, GameTitle, Platform, ReleaseDate, Developer,
PlatformId);");
}
?>
Any leads as to what I'm doing wrong will be greatly appreciated. I've
found nothing solid online and have tried many variations. I will continue
to figure this out and will update this post if I happen to run into it on
my own.
Thanks!

No comments:

Post a Comment