We help IT Professionals succeed at work.

php not able to read long column names - access

SameerMirza
SameerMirza used Ask the Experts™
on
Hi all,
Basically I am trying to use access table in a php program but unfortunatly php is able to read long column names.
If I cut the length of column name, it works (for the same column) so definatly something to do with the column name. e.g column name length = 35 or above.
Can any please let me know if I can get over this one? may be its set in php.ini (as far as I know, highly unlikely)
But it would be great if some one could provide work around for this one.

Thanks alot in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can specify aliases for columns in the SQL statement:

SELECT myreallyreallyreallyreallylongcolumnnamethatbreakseverything as mycolumn, othercolumn from mytable
That said, why would you want a column name over 35 chars long?
Top Expert 2010

Commented:
Please post an example of a column name that is not working, and the shorter name that does work.I agree that you may want to shorten your column names.  Also:1) Does the longer name work if you enclose it in square brackets, e.g. [MyColumnName] ?2) If you SQL statement refers to >1 table, is it possible that that column exists in >1 table but you did not qualify the column reference?It would be useful to see the SQL statement you are trying to execute...
PHP is fussy about other characters in its names like blanks or dashes. If your names have anything other than 0-9, a-z or _ in them then you will need aliases.
Top Expert 2010

Commented:
Not to mention that using anything other than letters, digits, and underscores is just bad practice anyway :)
Maybe - PHP goes a bit nuts with some XML because the data item names have colons in them. Perfectly legal in XML....

<ns:myName>
....
</ns:MyName>

Author

Commented:
I am sorry for not being able to reply earlier but thanks alot to all for help.
I think I should try alia first
Did you fix it? You might want to pick a solution to close this question.

Author

Commented:
nothing worked. I ha to cut column length.
I think php just cant read beyond certain length
I think it would be good idea to find the best solution for further referenace
PHP can support VERY long strings so it is unlikely to be that. I suppose there could be a limitation in the access database module.
You also never posted an example for us.
That said, I think any column name that is that long does not help anything, especially readability, so it is not really a problem anyway IMHO.

:D

Olly.

Author

Commented:
:) It wasnt tarribly long
but was somthing like this_column_nameislongormaybelonger
Coud be to do with the access module..
not sure now, been a while
PHP variables are supposed to be "unlimited" in length, but my suspicions would be on the driver (presumably ODBC) that connects to Access.

The PHP manual says

A valid variable name starts with a letter or underscore, followed by ANY number of letters, numbers, or underscores.

http://uk.php.net/manual/en/language.variables.basics.php

Author

Commented:
I was trying to execute quit a long statement so I am not 100% sure if the alisa approach was tested correctly
But what I remeber is that when I tried picking singe (longest) column it didnt worked unill I cut the coumn names in the database.
bportlock:
I don't think we are talking about variable names. The column name or alias would be presented in PHP as something like $record['columnname']. As the array index is just a string, I don't see how PHP would care what characters were in it (you would need to escape quotes of course).

SameerMirza:
I am assuming the query works in Access? If it does, just add " as shortname" after the column name in SQL view and try it again. If this works, copy and paste the query into your PHP script. I would be surprised if it didn't work (if you copy it accurately).
It seems that the PHP ODBC implementation is limited to 32 character column names

http://www.php.net/manual/en/function.odbc-field-name.php#81110

Author

Commented:
:) do you think I didnt tried that
That is first thing you do when writing complex sql
Unfortunatly I cant test any thing right now. Done and dusted for me but none of the above ideas work
If you have a access DB try testing it urself
Well I don't know what you tried. You were a bit vague. :D
If none of the solutions work, then please close the question by choosing your own answer (although bportlocks last post might be a contender depending on your point of view, as it seems to at least confirm the issue is there).

Author

Commented:
Justice.. :)
Thanks.