php - Parse all files in a directory to database doing nothing -
i have scheduled task uses wget download xml updates api directory.
if manually run in mysql workbench, parses xml file database properly:
load xml local infile 'c:\\wget\\getgame.php@id=773' replace table test.games (id, gametitle, platform, releasedate, developer, platformid);
i'm trying automate process, directory receive new files parsed. i've created .php script should check folder files , run sql query on in folder. (the folder cleans out on hour.)
running seems nothing. can confirm it's logging db, seems stop @ mysql query. (php not thing, yet, issue silly syntax error.)
<?php mysql_connect('localhost','root',''); mysql_select_db('test'); $files = glob('getgame.*'); foreach($files $file){ mysql_query("load xml local infile '".$file."' replace table test.games (id, gametitle, platform, releasedate, developer, platformid);"); } ?>
any leads i'm doing wrong appreciated. i've found nothing solid online , have tried many variations. continue figure out , update post if happen run on own.
thanks!
thanks attempts, i've found solution. first mistake assuming $file return full path when returns filename. created second variable holding path file, , concatenated 2 new variable used in mysql query. not perfect, worked in situation.
<?php mysql_connect('localhost','root','password') or die(mysql_error()); mysql_select_db('your_database'); $files = glob('filename.ext'); foreach($files $file) { $path = 'c:\\\\directory\\\\directory\\\\'; $fullpath = $path . $file; echo $fullpath; mysql_query("load xml local infile '".$fullpath."' replace table database.table (columns, to, parse, into, database)") or die("a mysql error has occurred. error: (" . mysql_errno() . ") " .mysql_error()); } echo "rows affected: " . mysql_affected_rows(); mysql_close(); ?>
i'm posting full script because i've yet see simple solution this. when googling "parse folder xml mysql" post second result, people out.
what do: long change $path variable folder holding xml file 4 backslashes instead of one, pass full path mysql in format accepts. script prints each file processed , prints number of effected rows after running. if there mysql error, prints error.
Comments
Post a Comment