Re: [PHP] Get a list of column field names from a MS Access table
On Sun, Mar 1, 2009 at 12:39 AM, Paul M Foster pa...@quillandmouse.com wrote: On Sat, Feb 28, 2009 at 06:54:25PM -0500, Andrew Ballard wrote: On Sat, Feb 28, 2009 at 6:08 PM, Paul M Foster pa...@quillandmouse.com wrote: On Sat, Feb 28, 2009 at 12:41:12AM +, Ashley Sheridan wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: snip That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? This is the SQL standard way of doing this. Both MySQL and PostgreSQL support it. Don't know about MSSQL. Paul -- Paul M. Foster Access is not MSSQL, and I'd hardly consider it standard SQL either. :-) To even connect to it from PHP, I think you'd need to either use a generic ODBC library or else the COM or DOTNET libraries to use something like Microsoft's ADO library or similar. I don't know about the connection details. My point was that querying the information_schema.columns and the like are the SQL standard way of querying the database engine to determine the details of the database and the tables. As I recall, MySQL had quite good tools for doing this, and PostgreSQL didn't, until the SQL standard way of querying the database about the database was implemented. Paul -- Paul M. Foster The information_schema path doesn't appear to work for MS Access. (Like I said, I'd hardly call it a standard SQL database.) However, I was able to get a column list using the ODBC library: ?php $db_name = 'C:\Path\To\Access\Data\File\MyDatabase'; $dsn = 'Driver={Microsoft Access Driver (*.mdb)};Dbq=' . $db_name . '.mdb'; $table_name = 'MyTable'; $db = odbc_connect($dsn, null, null); $result = odbc_columns($db, $db_name, , $table_name); echo odbc_result_all($result); ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Sat, 2009-02-28 at 00:40 -0500, Andrew Ballard wrote: On Fri, Feb 27, 2009 at 7:41 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: On Thu, Feb 26, 2009 at 4:01 PM, revDAVE c...@hosting4days.com wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A dirty way is to query the table where 1=2 to return no results select * from table where 1=2 That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? Ash www.ashleysheridan.co.uk I haven't ever seen information_schema in M$ Access. Andrew I guess then you could do something like this: $row_names = Array(); $query = SELECT TOP 1 * FROM table_name; $result = mssql_query($query); while($row = mssql_fetch_array($result)) { foreach($row as $key = $value) { $row_names[] = $key; } } I know it's a little messy there with the double loop, and I'm sure we can get rid of the while, but I've just woken up, so I'm not too compos mentis just yet! Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
revDAVE wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] Since I have never tried accessing Access from PHP I did some research. I found these examples on how to access Access... http://devzone.zend.com/article/4065-Reading-Access-Databases-with-PHP-and-PECL http://stackoverflow.com/questions/126513/php-and-ms-access-number-of-records-returned-by-select-query I also found this nice page: http://php.net/manual/en/function.odbc-columns.php what extension(s) are you using to access your DB. If it is odbc, then I see no problem accessing Access schema information. http://php.net/manual/en/function.odbc-columns.php#81227 will show you how... -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Sat, Feb 28, 2009 at 12:41:12AM +, Ashley Sheridan wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: snip That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? This is the SQL standard way of doing this. Both MySQL and PostgreSQL support it. Don't know about MSSQL. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Sat, Feb 28, 2009 at 6:08 PM, Paul M Foster pa...@quillandmouse.com wrote: On Sat, Feb 28, 2009 at 12:41:12AM +, Ashley Sheridan wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: snip That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? This is the SQL standard way of doing this. Both MySQL and PostgreSQL support it. Don't know about MSSQL. Paul -- Paul M. Foster Access is not MSSQL, and I'd hardly consider it standard SQL either. :-) To even connect to it from PHP, I think you'd need to either use a generic ODBC library or else the COM or DOTNET libraries to use something like Microsoft's ADO library or similar. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Sat, Feb 28, 2009 at 5:08 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2009-02-28 at 00:40 -0500, Andrew Ballard wrote: On Fri, Feb 27, 2009 at 7:41 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: On Thu, Feb 26, 2009 at 4:01 PM, revDAVE c...@hosting4days.com wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A dirty way is to query the table where 1=2 to return no results select * from table where 1=2 That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? Ash www.ashleysheridan.co.uk I haven't ever seen information_schema in M$ Access. Andrew I guess then you could do something like this: $row_names = Array(); $query = SELECT TOP 1 * FROM table_name; $result = mssql_query($query); while($row = mssql_fetch_array($result)) { foreach($row as $key = $value) { $row_names[] = $key; } } I know it's a little messy there with the double loop, and I'm sure we can get rid of the while, but I've just woken up, so I'm not too compos mentis just yet! Ash www.ashleysheridan.co.uk I don't even think TOP exists in Access, but I've never tried it there either. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Sat, Feb 28, 2009 at 06:54:25PM -0500, Andrew Ballard wrote: On Sat, Feb 28, 2009 at 6:08 PM, Paul M Foster pa...@quillandmouse.com wrote: On Sat, Feb 28, 2009 at 12:41:12AM +, Ashley Sheridan wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: snip That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? This is the SQL standard way of doing this. Both MySQL and PostgreSQL support it. Don't know about MSSQL. Paul -- Paul M. Foster Access is not MSSQL, and I'd hardly consider it standard SQL either. :-) To even connect to it from PHP, I think you'd need to either use a generic ODBC library or else the COM or DOTNET libraries to use something like Microsoft's ADO library or similar. I don't know about the connection details. My point was that querying the information_schema.columns and the like are the SQL standard way of querying the database engine to determine the details of the database and the tables. As I recall, MySQL had quite good tools for doing this, and PostgreSQL didn't, until the SQL standard way of querying the database about the database was implemented. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Thu, Feb 26, 2009 at 4:01 PM, revDAVE c...@hosting4days.com wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A dirty way is to query the table where 1=2 to return no results select * from table where 1=2 -- Bastien Cat, the other other white meat
Re: [PHP] Get a list of column field names from a MS Access table
On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: On Thu, Feb 26, 2009 at 4:01 PM, revDAVE c...@hosting4days.com wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A dirty way is to query the table where 1=2 to return no results select * from table where 1=2 That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Fri, Feb 27, 2009 at 4:58 PM, Bastien Koert phps...@gmail.com wrote: On Thu, Feb 26, 2009 at 4:01 PM, revDAVE c...@hosting4days.com wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A dirty way is to query the table where 1=2 to return no results select * from table where 1=2 -- Bastien Cat, the other other white meat I thought (and almost replied) the same, but the more I think about it, I'm not sure it would work. The query would return no results, so there wouldn't even be an array of empty values. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get a list of column field names from a MS Access table
On Fri, Feb 27, 2009 at 7:41 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2009-02-27 at 16:58 -0500, Bastien Koert wrote: On Thu, Feb 26, 2009 at 4:01 PM, revDAVE c...@hosting4days.com wrote: Newbie question: I would like to get a list of column field names from a MS Access table and hopefully get them returned in the ORIGINAL order (as they appear in access) Is there a sql query I could do to get this result? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A dirty way is to query the table where 1=2 to return no results select * from table where 1=2 That'll just return an empty result set, as in empty and with no fields output! In MySQL you can do this: SELECT column_name FROM information_schema.columns WHERE table_name = 'table_name' this might help with doing the same for M$Access? Ash www.ashleysheridan.co.uk I haven't ever seen information_schema in M$ Access. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php