Link to home
Start Free TrialLog in
Avatar of SameerMirza
SameerMirzaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php not able to read long column names - access

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
Avatar of ollyatstithians
ollyatstithians
Flag of United Kingdom of Great Britain and Northern Ireland image

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?
Avatar of Patrick Matthews
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.
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>
Avatar of SameerMirza

ASKER

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.
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.
:) 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
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).
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:) 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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Justice.. :)