PDA

View Full Version : use of reserved names for column titles


sweenster
06-28-2005, 08:42 PM
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.


$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.

Kid Charming
06-28-2005, 08:58 PM
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:


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:


SELECT
foo
,bar
,`reservedcolumnname`
FROM
table

sweenster
06-28-2005, 10:01 PM
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)

Kid Charming
06-28-2005, 10:30 PM
Oops. Force of habit. ;)

Try brackets or doublequotes instead of backticks: [reservedcolname]