472,779 Members | 2,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Using MySQL Command Load Data Infile

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
14 9649
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
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
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
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
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
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
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
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
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

"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

"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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: D. Alvarado | last post by:
Hello, I have discovered the beauties of the 'LOAD DATA INFILE' mysql command. However, I was wondering if someone could help me manipulate my command to accommodate for the 3 potential types of...
5
by: Phil Powell | last post by:
I've read some online resources that utilize various MySQL command-line actions to migrate data from Access to MySQL. The situation is this: a group of co-workers of mine will be using an Access...
2
by: Sandra | last post by:
Hi, I have this problem: I wish to put a text file into a mysql table. The text file entries are delimitated by tabs. Example: 123 456 7 89 (That is, '123' is a data, '456' is a data but...
4
by: Piotr | last post by:
Hi I have many files in Excel and I need to transfer them into MySQL, is tehere any free and easy solution ?
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
7
by: greywire | last post by:
So I need to load lots of data into my database. So I discover LOAD DATA INFILE. Great! This little gem loads my CSV in blazing times (compared to parsing the file and doing INSERT for each...
1
by: Jack | last post by:
Hi there MYSQL is loading a non printable character at the end of each row, clearly its a newline or ENTER character.. I have tried dos2unix.exe, a perl program that converts dos files to unix,...
1
by: Megi | last post by:
welcome, I input data form file to mysql with command: load data local infile.. The efect is that the data are duplicated or trippled..etc with every re-loading the script, but I need to load...
3
by: Eric_Dexter | last post by:
I am trying to take some data in file that looks like this command colnum_1 columnum_2 and look for the command and then cange the value in the collum(word) number indicated. I am under...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.