Page 1 of 1

DB FIELD NAME

Posted: Tue Nov 23, 2004 10:17 am
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

Posted: Tue Nov 23, 2004 11:32 am
by snicolas
Surpised nobody answered?
Am i a stupid or nobody has this problem?

Posted: Tue Nov 23, 2004 11:53 am
by patrikG
Patience, snicolas, and reading the manual helps as well: mssql functions - personally, I suspect mssql_field_name will do the job.

Posted: Tue Nov 23, 2004 11:54 am
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.

Posted: Tue Nov 23, 2004 4:18 pm
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;
}