Bulk loading with PHP & MySQL
Posted: Wed Jul 24, 2002 3:12 pm
Hi,
Can anyone tell me how to bulk load data to my database held on my ISP's
Apache server?
I have tried the following script which should point to a .txt file in my CGI bin but when I run it all I get is the following error message -
Parse error: parse error in /files/home3/jdwyer/conter.php on line 13.
I have also enclosed the salient parts of the .txt file I'm hoping to load, which was originally a word document which I saved as a .txt file
My script-
<?
$db_name = "jdwyer_**";
$table_name = "president";
$connection = @mysql_connect("*****", "jdwyer", "2*****8")
or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = LOAD DATA LOCAL INFILE "president.txt" INTO TABLE president;
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
if(!$result)
{
echo "<b>Something not added:</b> ", mysql_error <javascript:QuickRefPop('mysql_error');>();
exit;
}
if($result)
{
mysql_close <javascript:QuickRefPop('mysql_close');>($db);
print "Something added sucessfully!";
}
?>
Part of .txt file -
INSERT INTO president VALUES ('Washington','George',NULL,'Wakefield','VA','1732-02-22','1799-12-14');
INSERT INTO president VALUES ('Adams','John',NULL,'Braintree','MA','1735-10-30','1826-07-04');
INSERT INTO president VALUES ('Jefferson','Thomas',NULL,'Albemarle County','VA','1743-04-13','1826-07-04');
I have set the "Chmod" of the .txt file to 755 & try to run the PHP script by simply typing it's URL into the browser.
Thank you very much for any help.
JD.
(London)
Can anyone tell me how to bulk load data to my database held on my ISP's
Apache server?
I have tried the following script which should point to a .txt file in my CGI bin but when I run it all I get is the following error message -
Parse error: parse error in /files/home3/jdwyer/conter.php on line 13.
I have also enclosed the salient parts of the .txt file I'm hoping to load, which was originally a word document which I saved as a .txt file
My script-
<?
$db_name = "jdwyer_**";
$table_name = "president";
$connection = @mysql_connect("*****", "jdwyer", "2*****8")
or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = LOAD DATA LOCAL INFILE "president.txt" INTO TABLE president;
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
if(!$result)
{
echo "<b>Something not added:</b> ", mysql_error <javascript:QuickRefPop('mysql_error');>();
exit;
}
if($result)
{
mysql_close <javascript:QuickRefPop('mysql_close');>($db);
print "Something added sucessfully!";
}
?>
Part of .txt file -
INSERT INTO president VALUES ('Washington','George',NULL,'Wakefield','VA','1732-02-22','1799-12-14');
INSERT INTO president VALUES ('Adams','John',NULL,'Braintree','MA','1735-10-30','1826-07-04');
INSERT INTO president VALUES ('Jefferson','Thomas',NULL,'Albemarle County','VA','1743-04-13','1826-07-04');
I have set the "Chmod" of the .txt file to 755 & try to run the PHP script by simply typing it's URL into the browser.
Thank you very much for any help.
JD.
(London)