Go Back   CodingForums.com > :: Server side development > MySQL > Other Databases

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-28-2005, 07:42 PM   PM User | #1
sweenster
Regular Coder

 
Join Date: Sep 2002
Location: Scotland
Posts: 407
Thanks: 0
Thanked 0 Times in 0 Posts
sweenster is an unknown quantity at this point
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
sweenster is offline   Reply With Quote
Old 06-28-2005, 07:58 PM   PM User | #2
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
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
Kid Charming is offline   Reply With Quote
Old 06-28-2005, 09:01 PM   PM User | #3
sweenster
Regular Coder

 
Join Date: Sep 2002
Location: Scotland
Posts: 407
Thanks: 0
Thanked 0 Times in 0 Posts
sweenster is an unknown quantity at this point
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
sweenster is offline   Reply With Quote
Old 06-28-2005, 09:30 PM   PM User | #4
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
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..
Kid Charming is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:05 AM.


Advertisement
Log in to turn off these ads.