Murciano Posted May 27, 2010 Share Posted May 27, 2010 I need to read from a file and insert the files content into a MySQL column the table contains 3 fields id INT version VAR xmlver LONGTEXT What im wanting to do is grab the file, read it and then write it to a txt file, then the data from the txt file be read and sent to MySQL along with the id and xmlver details, i have seen this code snippet but when i try it it doesnt get me anywhere (confuses me) mysql_query('insert into tablename (columnname) values ("' . mysql_real_escape_string(file_get_contents('somefile')) . '");'); Whats the best way to do this?, code below (is it worth writing the XML to txt before insertion or can i insert the xml as is?) <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <?php if (isset($_POST['version'])) { $version = $_POST['version']; $data = file_get_contents("datafeed.xml"); $data = file_put_contents('datafeed.txt', $data); file_put_contents('version.txt', $version); } ?> <p align="center"> <input type="text" name="version" value="<?php include("version.txt"); ?>"/> <input type="submit" name="<?php echo $version; ?>" value="Update Server" /> </p> </form> Quote Link to comment Share on other sites More sharing options...
GetPutDelete Posted May 27, 2010 Share Posted May 27, 2010 You have two options, you can use MySql Load or you can parse the file into PHP and then insert it into the db. Quote Link to comment Share on other sites More sharing options...
Murciano Posted May 27, 2010 Author Share Posted May 27, 2010 Thanks, i have been looking at the LOAD DATA INFILE query earlier today, but am a little stumped at how to code it, would i need to run 2 mysql queries?.. 1 with the version and id and the other with LOAD DATA or could i put it all in one query?, if it can be done in 1 query would this be right <?php mysql_query("INSERT INTO file id='$id', version='$version' LOAD DATA INFILE 'datafeed.txt' INTO TABLE file.xmlver "); $result = mysql_query($query); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.