Jump to content

Retriveing column name for db with whitespace


budimir
Go to solution Solved by 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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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! :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.