//Written by Jonathan Hawkins email@example.com
//Use it for whatever I don\'t care. If you do something really cool with it
//send me a copy of the new code. We gotta share to get ahead! ;)
//If anyone can document it better, by all means do so and send me a copy. I suck at documenting.
//This script is for the poor schmucks like me who have no root access
//to their mySQL database at their web host and can\'t use the
// LOAD DATA INFILE command to import ASCII table dumps from other
//databases into mySQL. This baby does the trick.
//The script reads an ASCII text file dumped from any database
//and splits the delimited contents into an array.
//It then assigns each delimited field from the ASCII to a variable with a counter.
//Then it inserts the data into the mySQL database field at a time until it reaches the value of [$counter]
//At the moment it is set up for PIPE delimited ASCII. You\'ll have to figure out any other delimiter.Sorry.
//I have only tried this on small (less than 5meg) ASCII files and it seems to work fairly
//quickly. If you use it on anything larger you should verify your data before going live with it.
//To use it after it\'s configured, just call the script in your web browser via it\'s URL. If all
// goes well you will get a blank web page after it\'s done. (I\'m working on error checking routines)
//Otherwise you will get some nasty message from the PHP parser
//replace the connection variables to fit your situation
$connection=mysql_connect(\'localhost\',\'your_username\',\'your_password\')or die(\"Unable to access database at this time.\");
//reads the contents of the text file into array variable
$contents=file(\"your_textfile.txt\"); //make sure your path is correct
//counts the numbers of lines in the file
//Loops through each array value and assigns it a $variable[$counter]
//then inserts each sequentially into the DB table
//The $utid variable and the $idletter variable can be renamed to match your
//At present it is set up to update only two fields.
//I have used this format for up to twenty-one fields in a 16,000 record DB.
//Just add extra $variable[$counter] items to the list() and be sure to duplicate
//them in the $sql variable according to the format you see.
$sql=\"INSERT INTO $table_name VALUES (\'$utid[$counter]\',\'$idletter[$counter]\')\";
Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.