Problem using date variable in php script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jim.kelly

    Problem using date variable in php script

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

    $result = mysql_query('LO AD 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...ev erything 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("ym d"); <- )

    Thanks for your help!
    Jim

  • BKDotCom

    #2
    Re: Problem using date variable in php script

    You've got the whole query surrounded by single quotes..
    replace ".$today." with '.$today.'

    jim.kelly wrote:[color=blue]
    > $result = mysql_query('LO AD DATA LOCAL INFILE "NYSE_".$today. ".txt"
    > INTO TABLE main FIELDS TERMINATED BY "," LINES TERMINATED BY ","');
    >[/color]

    Comment

    • BKDotCom

      #3
      Re: Problem using date variable in php script


      I should add that

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

      is always handy

      Comment

      • jim.kelly

        #4
        Re: Problem using date variable in php script

        I'll add that too. I'm new to PHP so I appreciate the tip.
        Jim

        Comment

        • jim.kelly

          #5
          Re: Problem using date variable in php script

          Thanks! That got me going!!
          Jim

          Comment

          • Tim Van Wassenhove

            #6
            Re: Problem using date variable in php script

            On 2005-05-05, BKDotCom <bkfake-google@yahoo.co m> wrote:[color=blue]
            >
            > I should add that
            >
            > if ( $result == false )
            > mysql_error();
            >[/color]

            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>

            Comment

            • Mladen Gogala

              #7
              Re: Problem using date variable in php script

              On Wed, 04 May 2005 18:20:05 -0700, jim.kelly wrote:
              [color=blue]
              >
              > $result = mysql_query('LO AD DATA LOCAL INFILE "NYSE_".$today. ".txt"
              > INTO TABLE main FIELDS TERMINATED BY "," LINES TERMINATED BY ","');[/color]

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

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

              Comment

              Working...