DB FIELD NAME

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

DB FIELD NAME

Post by snicolas »

I am using PHP and MSSQL.
My problem is regarding column name in mssql.
Is there a function or a way to be able to display the name of a column whatever the case of this DB field.
I explain.
My Colum in MSSQL is called CompanyID (note Capital C and ID).
If I try to display the content of this column like $row["companyid"] I will not return any result.
But If respect the case of this fields as $row["CompanyID"] the right record will be display.

My database contain lots of fields that are Upper/Lower case, I am trying to find a way to convert everything to lower case without having to do it manually on the db.

Thanks

S
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

Surpised nobody answered?
Am i a stupid or nobody has this problem?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Patience, snicolas, and reading the manual helps as well: mssql functions - personally, I suspect mssql_field_name will do the job.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Not sure if there is specific MSSQL syntax for this, but in MySQL, you'd have to change each column name manually, to be all lower case. The syntax for a query like that would be:

Code: Select all

ALTER TABLE my_table CHANGE CompanyID companyid int(2)
Of course, the column type can be whatever you want.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

and if you want to do it the painfull way:

Code: Select all

// asuming a row - resultset is in $row
$lckeys = array();
foreach($row as $column => $value)
{
    $lckeys[strtolower($column)] = $value;
}
Post Reply