By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Using MySQL Command Load Data Infile

P: n/a
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"

$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\" into table addresses";
$result = mysql_query($SQL) or die(mysql_error());

The file is located in the same directory as my .PHP file.

How do I generate a relative address for this file so that it can be found?
I'm running on XP Prof..

Thanks...

Bruce
Jul 17 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Bruce A. Julseth wrote:
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"

$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\" into table addresses";
$result = mysql_query($SQL) or die(mysql_error());

The file is located in the same directory as my .PHP file.

How do I generate a relative address for this file so that it can be
found? I'm running on XP Prof..


I suspect MySQL requires a full pathname to the file, because you're running
a SQL command. Although the file is relative to the PHP script MySQL has no
conception of that relative path. Try it with a full pathname and you
should be fine.

If it was a Unix/Linux box you'd need to make sure the MySQL server has
permissions to read from that directory and file, but you probably won't
have this problem on Windows.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

P: n/a
Thanks for the response. I have a problem using absolute path names. I am
developing on a local machine with Apache. When completed, I will upload to
an ISP and I have no idea what the absolute path to my file will be. Any
suggestions here??

Or, does someone else have an idea on how I can use an absolute path.

Thanks...

Bruce

"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10***************@216.128.74.129...
Bruce A. Julseth wrote:
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"

$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\" into table addresses";
$result = mysql_query($SQL) or die(mysql_error());

The file is located in the same directory as my .PHP file.

How do I generate a relative address for this file so that it can be
found? I'm running on XP Prof..
I suspect MySQL requires a full pathname to the file, because you're

running a SQL command. Although the file is relative to the PHP script MySQL has no conception of that relative path. Try it with a full pathname and you
should be fine.

If it was a Unix/Linux box you'd need to make sure the MySQL server has
permissions to read from that directory and file, but you probably won't
have this problem on Windows.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

Jul 17 '05 #3

P: n/a
In message <40********@news1.prserv.net>, Bruce A. Julseth
<br*****@attglobal.net> writes
Thanks for the response. I have a problem using absolute path names. I am
developing on a local machine with Apache. When completed, I will upload to
an ISP and I have no idea what the absolute path to my file will be. Any
suggestions here??

Or, does someone else have an idea on how I can use an absolute path.
I think you need to look at some of the server variables which help with
paths. Whilst you don't know what the absolute path will be, surely you
will know the relative path?

Thanks...

Bruce

"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10***************@216.128.74.129...
Bruce A. Julseth wrote:
> When I execute this SQL statement in my PHP code, I get an error
> "File '.\Address.txt' not found (Errcode: 2)"
>
> $File = addslashes(".\Address.txt");
> $SQL = "Load Data InFile \"" . $File . "\" into table addresses";
> $result = mysql_query($SQL) or die(mysql_error());
>
> The file is located in the same directory as my .PHP file.
>
> How do I generate a relative address for this file so that it can be
> found? I'm running on XP Prof..


I suspect MySQL requires a full pathname to the file, because you're

running
a SQL command. Although the file is relative to the PHP script MySQL has

no
conception of that relative path. Try it with a full pathname and you
should be fine.

If it was a Unix/Linux box you'd need to make sure the MySQL server has
permissions to read from that directory and file, but you probably won't
have this problem on Windows.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/



--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #4

P: n/a
You suggested "Server Variables." I'm new to this game. Can you give me a
few suggestions?

Thanks...

Bruce

"Five Cats" <ca*******@[127.0.0.1]> wrote in message
news:oX**************@[127.0.0.1]...
In message <40********@news1.prserv.net>, Bruce A. Julseth
<br*****@attglobal.net> writes
Thanks for the response. I have a problem using absolute path names. I am
developing on a local machine with Apache. When completed, I will upload toan ISP and I have no idea what the absolute path to my file will be. Any
suggestions here??

Or, does someone else have an idea on how I can use an absolute path.


I think you need to look at some of the server variables which help with
paths. Whilst you don't know what the absolute path will be, surely you
will know the relative path?

Thanks...

Bruce

"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10***************@216.128.74.129...
Bruce A. Julseth wrote:

> When I execute this SQL statement in my PHP code, I get an error
> "File '.\Address.txt' not found (Errcode: 2)"
>
> $File = addslashes(".\Address.txt");
> $SQL = "Load Data InFile \"" . $File . "\" into table addresses";
> $result = mysql_query($SQL) or die(mysql_error());
>
> The file is located in the same directory as my .PHP file.
>
> How do I generate a relative address for this file so that it can be
> found? I'm running on XP Prof..

I suspect MySQL requires a full pathname to the file, because you're

running
a SQL command. Although the file is relative to the PHP script MySQL has
no
conception of that relative path. Try it with a full pathname and you
should be fine.

If it was a Unix/Linux box you'd need to make sure the MySQL server has
permissions to read from that directory and file, but you probably

won't have this problem on Windows.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/



--
Five Cats
Email to: cats_spam at uk2 dot net

Jul 17 '05 #5

P: n/a
On Mon, 28 Jun 2004 12:27:30 -0400, "Bruce A. Julseth"
<br*****@attglobal.net> wrote:
You suggested "Server Variables." I'm new to this game. Can you give me a
few suggestions?

PLEASE stop top posting.

Server Variables:
With bourne: (/bin/sh) and Bash (/usr/bin/bash>

$ VARIABLENAME="variable contents"
$ export VARIABLE NAME

With K shell (/usr/bin/ksh)

export VARIABLENAME="viarable contents"

With CSH (/bin/csh>

setenv VARIABLENAME "variable contents"
type: "set" or "printenv" to see what your settings are now.

Oh, and did I mention you should stop top posting? :)
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://www.databasix.com
================================================== =========================
Jul 17 '05 #6

P: n/a
In message <40********@news1.prserv.net>, Bruce A. Julseth
<br*****@attglobal.net> writes
You suggested "Server Variables." I'm new to this game. Can you give me a
few suggestions?

http://www.php.net/manual/en/languag...predefined.php

Also create the following script and look at it's output, on both
machines:

<?php
phpinfo();
?>

and see

http://uk2.php.net/manual/en/function.phpinfo.php

Thanks...

Bruce

"Five Cats" <ca*******@[127.0.0.1]> wrote in message
news:oX**************@[127.0.0.1]...
In message <40********@news1.prserv.net>, Bruce A. Julseth
<br*****@attglobal.net> writes
>Thanks for the response. I have a problem using absolute path names. I am
>developing on a local machine with Apache. When completed, I will uploadto >an ISP and I have no idea what the absolute path to my file will be. Any
>suggestions here??
>
>Or, does someone else have an idea on how I can use an absolute path.


I think you need to look at some of the server variables which help with
paths. Whilst you don't know what the absolute path will be, surely you
will know the relative path?
>
>Thanks...
>
>Bruce
>
>"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
>news:10***************@216.128.74.129...
>> Bruce A. Julseth wrote:
>>
>> > When I execute this SQL statement in my PHP code, I get an error
>> > "File '.\Address.txt' not found (Errcode: 2)"
>> >
>> > $File = addslashes(".\Address.txt");
>> > $SQL = "Load Data InFile \"" . $File . "\" into table addresses";
>> > $result = mysql_query($SQL) or die(mysql_error());
>> >
>> > The file is located in the same directory as my .PHP file.
>> >
>> > How do I generate a relative address for this file so that it can be
>> > found? I'm running on XP Prof..
>>
>> I suspect MySQL requires a full pathname to the file, because you're
>running
>> a SQL command. Although the file is relative to the PHP script MySQLhas >no
>> conception of that relative path. Try it with a full pathname and you
>> should be fine.
>>
>> If it was a Unix/Linux box you'd need to make sure the MySQL server has
>> permissions to read from that directory and file, but you probablywon't >> have this problem on Windows.
>>
>> --
>> Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
>
>


--
Five Cats
Email to: cats_spam at uk2 dot net



--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #7

P: n/a
On Sun, 27 Jun 2004 23:28:57 -0400, "Bruce A. Julseth" <br*****@attglobal.net>
wrote:
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"

$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\" into table addresses";
$result = mysql_query($SQL) or die(mysql_error());

The file is located in the same directory as my .PHP file.


Then then command you want would probably be LOAD DATA LOCAL INFILE - note the
LOCAL. Without it, I believe the path is relative to the database data
directory. Or you need an absolute path and stick with LOAD DATA INFILE,
assuming that the MySQL database is running on the same machine as the
webserver.

You can get the current directory with getcwd.

http://uk2.php.net/manual/en/function.getcwd.php

Or if you're not necessarily in that directory (perhaps in an include file?)
then dirname(__FILE__).

http://uk2.php.net/manual/en/function.dirname.php

I also remember there are security restrictions on usage of LOAD DATA LOCAL
INFILE that depend on MySQL version and compile-time options (possibly
changeable in my.cnf?). See the manual for more information.

http://dev.mysql.com/doc/mysql/en/LOAD_DATA.html
http://www.mysql.com/news-and-events...000000012.html

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #8

P: n/a
Okay, I'll be happy to stop top posting if I only knew what it is? What is
"top Posting?"

Bruce

"Gary L. Burnore" <gb******@databasix.com> wrote in message
news:cb**********@blackhelicopter.databasix.com...
On Mon, 28 Jun 2004 12:27:30 -0400, "Bruce A. Julseth"
<br*****@attglobal.net> wrote:
You suggested "Server Variables." I'm new to this game. Can you give me a
few suggestions?
PLEASE stop top posting.

Server Variables:
With bourne: (/bin/sh) and Bash (/usr/bin/bash>

$ VARIABLENAME="variable contents"
$ export VARIABLE NAME

With K shell (/usr/bin/ksh)

export VARIABLENAME="viarable contents"

With CSH (/bin/csh>

setenv VARIABLENAME "variable contents"
type: "set" or "printenv" to see what your settings are now.

Oh, and did I mention you should stop top posting? :)
--
gburnore@databasix dot com
--------------------------------------------------------------------------

- How you look depends on where you go.
-------------------------------------------------------------------------- - Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== ========================= Want one? GET one! http://www.databasix.com

================================================== =========================
Jul 17 '05 #9

P: n/a
Bruce A. Julseth wrote:
Okay, I'll be happy to stop top posting if I only knew what it is? What is
"top Posting?"

Bruce

<snip>

just that. you are responding at the TOP of the orignal message when
netiquette dictates it should FOLLOW (be at the bottom) of the original
message... and if the original message is too long, it can be
appropriate to "snip" the irrelevant parts in your reply.

....like this response.

Michael Austin.
Jul 17 '05 #10

P: n/a

"Michael Austin" <ma*****@firstdbasource.com> wrote in message
news:Xg*****************@newssvr24.news.prodigy.co m...
Bruce A. Julseth wrote:
Okay, I'll be happy to stop top posting if I only knew what it is? What is "top Posting?"

Bruce

<snip>

just that. you are responding at the TOP of the orignal message when
netiquette dictates it should FOLLOW (be at the bottom) of the original
message... and if the original message is too long, it can be
appropriate to "snip" the irrelevant parts in your reply.

...like this response.

Michael Austin.


Okay... I'll try to remember this in the future. I've only been using
newgroups for about 20 years and this is the first time anyone has told me
that I was wrong...

Bruce

Jul 17 '05 #11

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:qq********************************@4ax.com...
On Sun, 27 Jun 2004 23:28:57 -0400, "Bruce A. Julseth" <br*****@attglobal.net> wrote:
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"

$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\" into table addresses";
$result = mysql_query($SQL) or die(mysql_error());

The file is located in the same directory as my .PHP file.
Then then command you want would probably be LOAD DATA LOCAL INFILE -

note the LOCAL. Without it, I believe the path is relative to the database data
directory. Or you need an absolute path and stick with LOAD DATA INFILE,
assuming that the MySQL database is running on the same machine as the
webserver.
I'll give this a try. I like it and hope it works.

You can get the current directory with getcwd.
I used this and it solved the problem.

http://uk2.php.net/manual/en/function.getcwd.php

Or if you're not necessarily in that directory (perhaps in an include file?) then dirname(__FILE__).

http://uk2.php.net/manual/en/function.dirname.php

I also remember there are security restrictions on usage of LOAD DATA LOCAL INFILE that depend on MySQL version and compile-time options (possibly
changeable in my.cnf?). See the manual for more information.

http://dev.mysql.com/doc/mysql/en/LOAD_DATA.html
http://www.mysql.com/news-and-events...000000012.html
I'll give these a try. Thanks.


--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

Jul 17 '05 #12

P: n/a
Bruce A. Julseth wrote:
"Michael Austin" <ma*****@firstdbasource.com> wrote in message
news:Xg*****************@newssvr24.news.prodigy.co m...
Bruce A. Julseth wrote:
Okay, I'll be happy to stop top posting if I only knew what it is? What
is
"top Posting?"

Bruce

<snip>

just that. you are responding at the TOP of the orignal message when
netiquette dictates it should FOLLOW (be at the bottom) of the original
message... and if the original message is too long, it can be
appropriate to "snip" the irrelevant parts in your reply.

...like this response.

Michael Austin.

Okay... I'll try to remember this in the future. I've only been using
newgroups for about 20 years and this is the first time anyone has told me
that I was wrong...


.... me too, and I have always been aware of it.. :)

Bruce


Michael Austin.
Jul 17 '05 #13

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:qq********************************@4ax.com...
On Sun, 27 Jun 2004 23:28:57 -0400, "Bruce A. Julseth" <br*****@attglobal.net> wrote:
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"

$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\" into table addresses";
$result = mysql_query($SQL) or die(mysql_error());

The file is located in the same directory as my .PHP file.
Then then command you want would probably be LOAD DATA LOCAL INFILE -

note the LOCAL. Without it, I believe the path is relative to the database data
directory. Or you need an absolute path and stick with LOAD DATA INFILE,
assuming that the MySQL database is running on the same machine as the
webserver.
I get an error message that this command (LOAD DATA INFILE....) is not
allowed with this version of MySQL. I'm using version 4.0.14-max-debug.

You can get the current directory with getcwd.

http://uk2.php.net/manual/en/function.getcwd.php

Or if you're not necessarily in that directory (perhaps in an include file?) then dirname(__FILE__).

http://uk2.php.net/manual/en/function.dirname.php

I also remember there are security restrictions on usage of LOAD DATA LOCAL INFILE that depend on MySQL version and compile-time options (possibly
changeable in my.cnf?). See the manual for more information.

http://dev.mysql.com/doc/mysql/en/LOAD_DATA.html
http://www.mysql.com/news-and-events...000000012.html

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


Jul 17 '05 #14

P: n/a
On Wed, 30 Jun 2004 13:37:17 -0400, "Bruce A. Julseth" <br*****@attglobal.net>
wrote:
I get an error message that this command (LOAD DATA INFILE....) is not
allowed with this version of MySQL. I'm using version 4.0.14-max-debug.


That's why I posted:
I also remember there are security restrictions on usage of LOAD DATA
LOCAL INFILE that depend on MySQL version and compile-time options (possibly
changeable in my.cnf?). See the manual for more information.

http://dev.mysql.com/doc/mysql/en/LOAD_DATA.html
http://www.mysql.com/news-and-events...000000012.html


--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.