Jump to content

Retriveing column name for db with whitespace


budimir

Recommended Posts

I have to connect to mssql database and everything is working fine until I reach db filed which has whitespace in a name. Is there any workaround for this?

 

code example

while($row = sqlsrv_fetch_array( $rezultat_ms, SQLSRV_FETCH_ASSOC)){
    $kataloski_broj = $row["No_"];
    $naziv = $row["Description"];
    $kategorija = $row["Item Category Code"];
    $grupa_proizvoda = $row["Product Group Code"];

Error

Notice: Undefined index: Item Category Code in C:\wampserver\www\erp\katalog_pribora\sync\sync_item.php on line 28

First two variables are OK, but second two are failing beacuse of a space in a name. I can not change db field names.

 

Any workarounds?

There is a lot of information in $row, around 15 variables in total. VARCHAR, DECIMAL, INT...

 

Everything is working fine for me, until I have to read a column that has a space in the name. There it fails. Tried to test it on test databse and I managed to simulate my problem, but I can't change working db.

OK, I found a problem... Of course it's stupid me... I have limited my query to only two columns while I was testing, and didn't realise it when I wanted to see everything.

 

After I selected columns I needed, error was gone! Magic! :)

 

Sorry to disturbe you! :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.