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)
Bulk loading with PHP & MySQL
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try:
and read this:
http://www.devnetwork.net/forums/viewtopic.php?t=1030
Mac
Code: Select all
<?php
$db_name = 'jdwyer_**';
$table_name = 'president';
$connection = @mysql_connect('*****', 'jdwyer', '2*****8') or die("Couldn't connect.");
$db = @mysql_select_db($db_name) or die("Couldn't select database.");
$sql = "LOAD DATA LOCAL INFILE 'president.txt' INTO TABLE president";
@mysql_query($sql) or die("Couldn't execute query.".mysql_error());
@mysql_close();
print 'Something added sucessfully!';
?>http://www.devnetwork.net/forums/viewtopic.php?t=1030
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
That's why I posted the link to the sticky in the PHP forum. Basically you can't execute a javascript function from within PHP and you definitely will get parse errors if you put things like:
into your PHP code.
Mac
Code: Select all
mysql_error <javascript:QuickRefPop('mysql_error');> ()Mac