php and mysql

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

    php and mysql

    Hi,

    Can anybody tell me the difference between the two insertions:

    $price=18.45;

    INSERT INTO tbl (price) VALUES ($price);
    INSERT INTO tbl (price) VALUES ('$price');

    price is DECIMAL(10,2) in tbl.


    Thanks.
  • Tony Marston

    #2
    Re: php and mysql

    One is between quotes, the other is not.

    Strings must be between quotes, numbers may or may not be quoted.

    --
    Tony Marston

    This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



    "cnh" <cnh291@hotmail .com> wrote in message
    news:5278e8a4.0 410231848.7399f fb0@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > Can anybody tell me the difference between the two insertions:
    >
    > $price=18.45;
    >
    > INSERT INTO tbl (price) VALUES ($price);
    > INSERT INTO tbl (price) VALUES ('$price');
    >
    > price is DECIMAL(10,2) in tbl.
    >
    >
    > Thanks.[/color]


    Comment

    • Ilija Studen

      #3
      Re: php and mysql

      Tony Marston wrote:[color=blue]
      > One is between quotes, the other is not.
      >
      > Strings must be between quotes, numbers may or may not be quoted.
      >[/color]

      Also note that almost all DBs will not let you insert unquoted data,
      even if it is number.

      Comment

      • Tony Marston

        #4
        Re: php and mysql


        "Ilija Studen" <remove_this_il ija.studen@gmai l.com> wrote in message
        news:2u4dv8F24v ofbU2@uni-berlin.de...[color=blue]
        > Tony Marston wrote:[color=green]
        >> One is between quotes, the other is not.
        >>
        >> Strings must be between quotes, numbers may or may not be quoted.
        >>[/color]
        >
        > Also note that almost all DBs will not let you insert unquoted data, even
        > if it is number.[/color]

        But there are some that will reject a number if it is enclosed in quotes,
        expecting it to be a literal instead of a quoted string.

        --
        Tony Marston

        This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




        Comment

        • Felix

          #5
          Re: php and mysql

          Let's get a little specific, shall we?

          I work with both PostgreSQL (7.0) and MySQL (3.23.?) and from what I've seen
          they both accept numbers either in quoted or unquoted form. But I'm not sure
          whether this is SQL92 or not.

          My advice: to be on the safe side don't quote numbers in queries.

          From the shadows,
          Felix

          Comment

          Working...