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

Problem using date variable in php script

P: n/a
Hi all,
I'm having trouble with the following line of code in my php script:

$result = mysql_query('LOAD DATA LOCAL INFILE "NYSE_".$today.".txt"
INTO TABLE main FIELDS TERMINATED BY "," LINES TERMINATED BY ","');

I've tested $today and it gives the correctly formatted date. And when
I hard code the file name, the mysql database is filled as
advertised...everything is fine. But I've tried every variation of
date variable I can think of and it fails. Well, actually no error,
but the above line of code doesn't seem to run because the table stays
empty.

'$today' is required because the file name changes each day and has the
current date in its name. (code -> $today=date("ymd"); <- )

Thanks for your help!
Jim

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


P: n/a
You've got the whole query surrounded by single quotes..
replace ".$today." with '.$today.'

jim.kelly wrote:
$result = mysql_query('LOAD DATA LOCAL INFILE "NYSE_".$today.".txt"
INTO TABLE main FIELDS TERMINATED BY "," LINES TERMINATED BY ","');


Jul 17 '05 #2

P: n/a

I should add that

if ( $result == false )
mysql_error();

is always handy

Jul 17 '05 #3

P: n/a
I'll add that too. I'm new to PHP so I appreciate the tip.
Jim

Jul 17 '05 #4

P: n/a
Thanks! That got me going!!
Jim

Jul 17 '05 #5

P: n/a
On 2005-05-05, BKDotCom <bk***********@yahoo.com> wrote:

I should add that

if ( $result == false )
mysql_error();


imho, i prefer to read/write
if (!$result)

than
if ($result == false)
if ($result != true)
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #6

P: n/a
On Wed, 04 May 2005 18:20:05 -0700, jim.kelly wrote:

$result = mysql_query('LOAD DATA LOCAL INFILE "NYSE_".$today.".txt"
INTO TABLE main FIELDS TERMINATED BY "," LINES TERMINATED BY ","');


The text within the single quotes is not interpreted.
What you want is the following:
$result = mysql_query("LOAD DATA LOCAL INFILE NYSE_.$today.txt ".
'INTO TABLE main FIELDS TERMINATED BY "," LINES TERMINATED BY ","');

--
Egoist: A person of low taste, more interested in themselves than in me.

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.