Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    use of reserved names for column titles

    There's nothing wrong with my code below but the problem is that i've used 2 reserved keywords as column names - browse and full.

    PHP Code:
    $query "INSERT INTO fs_stats(ip, addr, browse, vers, refer, OS, os_vers, res, full) VALUES ('".$ipad."', '".$addr."', '".$brwse."', '".$vers."', '".$referer."', '".$os."', '".$vr."', 'JS Disabled', '".$full."');"
    My first question is is there any simple change I can make to the line above that will make this code work, secondly if not how would you rename the columns to unreserved names?

    (I dont have administrative access and the administrator is on holiday for the next fortnight!)

    Database is SQL server2000 and has anonymous user access to the database via PHP and a DSN set up.
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Generally, it's a bad idea to use reserved names, so the preferred solution is to change the name. In SQL, you can use the ALTER TABLE command to do this:

    Code:
    ALTER TABLE
     tablename
    CHANGE
     oldcolumname
     newcolumname columnspecs
    If you don't have ALTER privs, you can put the column names in backticks to get around the reserved problem:

    Code:
    SELECT
     foo
    ,bar
    ,`reservedcolumnname`
    FROM
     table

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried to alter it but again it wouldnt update because the column name is a keyword.

    The ` trick didnt work either i'm afraid :-(

    (Remember this is MSSQL i'm using not MYSQL)
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops. Force of habit.

    Try brackets
    Edit: or doublequotes
    instead of backticks: [reservedcolname]
    Last edited by Kid Charming; 06-28-2005 at 09:39 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •