Stevens
09-08-2003, 06:58 PM
Folks,
I have a 400-record database in MS Access that I need to transfer to MySQL. Does anyone have any idea how I might be able to create a SQL script from the MS Access db that I can run in phpMyAdmin that will automatically create the records?
ERIC
Chris
09-08-2003, 08:40 PM
Export it as a delimited text file, I like to use | as a delimiter because it isn't going to appear in your text (as opposed to a comma which could).
Then you can write a simple import script.
php's file() function parses each line of a text file into an array, so do that and it'll put each record into an array. Then you can use the array walk function to process each record and insert it. Here is an example I've used.
<?
$quotelist = file("$url");
$db = mysql_connect("localhost", "username", "password");
if (!$db) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit();}
mysql_select_db("quotes", $db);
function addquote($element){
$quote_array = explode("|",$element);
$author = $quote_array[0];
$quote = $quote_array[1];
$attribution = $quote_array[2];
global $db;
$result1 = mysql_query("INSERT Into quotes SET author = '$author', quote = '$quote', attribution = '$attribution'", $db);
if (!$result1) { echo("<P>Error performing query: " . mysql_error() . "</P>");
exit();
}
}
array_walk($quotelist, 'addquote');
?>
What you'd do is pass the script an argument called "url" which is the location of the text file.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.