I am running linux from bluehost and have PDO installed.
I wish to access *.mdb info, however I cannot seem to get past the connection string for PDO in this case.
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdb;Uid=Admin");
Generates error:
SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified
I know the the path is correct:
/home1/[Removed]/pss/pss.md
Does anyone know of any solution to this issue using the PDO library?
As requested, expanding on my comment.
MDB support on Linux is limited; although MDB Tools (used by PDO on Linux) does provide partial read-only support, the general status seems far from production ready, as the FAQ says
1.2 What does MDB Tools do
MDB Tools is an open source suite of libraries and utilities to read
(and soon write) MDB database files.
1.6 Is there a roadmap?
Roughly, the plan moving forward looks like this.
Add index scan capability to libmdb and the SQL engine with a query
plan generator.
Add support for adding rows to existing tables and an mdb-import
tool.
Add full write support to libmdb and libmdbsql.
Extract queries, table properties, VBA script, forms.
mdb-check database consistancy checker and recovery tool.
Add joins.
Ability to add tables.
If you only need to read the .mdb, then installing mdbtools might be good enough.
If you need read-write, or any of the features on the roadmap, and must use .mdb, then use a Windows or possibly Mac host
If the .mdb is just a datasource, export it to SQL and use MySQL or PostGres (PostGres seems to have better ODBC support for Windows, if this is relevant to your project)
Related
This is a pretty straightforward question: is there any way of creating an MS Access database file from scratch using PHP? I strongly suspect the answer is no out of the box (using PDO with the ODBC driver pretty clearly demands an existing file for the connection string), but perhaps there’s a library I haven’t found. Currently I’m using an empty .accdb file as a template and making a copy before CREATE-ing tables in it, but I’d like to skip that step for security reasons if nothing else.
You can't, because the ODBC driver needs a database(!) to connect to.
Your current approach, copying a template file, is clean and simple and, except if the file can be replaced, also safe.
My setup: IIS 7.5, PHP 5.4, Windows 7
I've trying to create a COM Object through PHP but I continue to get access denied. I've also followed a handful of tutorials on how to "grant access" to the ISUR to create the object but to no avail. I read the installation portion relevant to COM interfacing that says:
As of PHP 5.3.15 / 5.4.5, this extension requires php_com_dotnet.dll
to be enabled inside of php.ini in order to use these functions.
Previous versions of PHP enabled these extensions by default.
You are responsible for installing support for the various COM objects
that you intend to use (such as MS Word); we don't and can't bundle
all of those with PHP.
I've enabled the php_com_dotnet.dll file within the ini file but I still can't seem to create the COM object for Excel. Then if you read the second paragraph it says that you have to install support for the various COM objects you intend to use but doesn't specify how to go about doing that.
Question: How do I install support for the MS Excel COM object?
Any help would be appreciated. I've researched this issue but haven't found very much documentation out there.
Don't do this. You're in for a world of pain trying to launch Excel in a web application, especially from PHP.
Microsoft Office apps such as Word and Excel are not designed for server side use. When you try to instantiate an Excel "COM object" you're spinning up a full instance of Excel as a separate process. That is hugely expensive and will never scale. Not only that, to add to your woes, if for whatever reason your script can't release and shut down Excel you'll end up with tens or possibly hundreds of orphaned Excel processes hanging around in memory.
Try something like: https://github.com/PHPOffice/PHPExcel if you need to read and write Excel compatible spreadsheets.
Can anyone tell me if there is limited SQL support using unixODBC drivers on Ubuntu with PHP? I've setup a basic lamp server on Ubuntu 11.10, and I'm trying to query an Access database. I've installed php5-odbc and MDB Tools. Here is some sample code:
<?php
$conn = odbc_connect('logindb','','');
if (!$conn) {
echo "failed";
}
$sql = "SELECT * FROM class";
//$sql = "SELECT class.desc, event_classes.event_class_id FROM class inner join
//event_classes on class.class_id = event_classes.class_id";
$rs = odbc_exec($conn, $sql);
while ($d = odbc_fetch_array($rs)) {
var_dump($d);
}
?>
The first query, the simple select, works just fine. However, when trying to perform a join (second commented query), I receive 0 records. I was able to run the SQL successfully in the SQL editor within Access, so I know my SQL is correct and the join is working there. Has anyone had any experience with this? I know Linux wasn't made to be compatible with proprietary Microsoft products, but unfortunately I have to make reading an Access database on Ubuntu work. Any help is greatly appreciated.
mdbtools on sourceforge has not been updated since 2004. I see someone has put it on github and seems to have made a few small changes. The SQL support in it was never that good, it was read only and I know from experience trying it under Perl with DBD::ODBC a lot of the tests failed. I think you are going to have a hard time with it.
There are other more reliable ways to access a MS Access database from Linux but they are all to my knowledge commercial. To access a MS Access database from Linux I know of the following:
Easysoft have an ODBC-ODBC Bridge (which can be used to access a MS Access DB on a windows machine using the MS Access ODBC Driver) but it requires installing a service on the Windows machine. Easysoft also have a MS Access ODBC driver which can be used for direct access to the mdb/accdb file so long as it is visible from Linux.
There are other commercial ODBC bridges from Openlink.
If anyone happens to be looking for a hacky solution, I ended up using mdb-tools to convert the access database to csv files (1 per table), and then iterating through the csv performing a "manual" join. Not the best solution, but it ended up working for fairly small tables. Hope it helps!
Is it possible to write .MDF files using PHP. I have a simple HTML table - x columns, y rows that I wish to convert into a MS Access dataset. There are no foreign keys or anything exotic, just a number of rows and columns.
I have Google searched but the only advice I seem to be able to find is to save it as a .CSV. Unfortunately this isn't acceptable for my client. They want to simply be able to double click the icon and have the database load up in Access (Seems you have to import csv files and can't just double click them).
Those are actually two different problems:
1) Parsing HTML to separate values
Since you seem to have found a way to export to csv, I won't be answering this. You already got your parser then.
2) Create an mdb file.
You can use odbc to talk to Access, that is, if you are in Windows. That means that PHP must be installed on a Windows machine. I'm not aware of any Linux drivers for Access..
You can use odbc_connect to connect to the database:
$conn = odbc_connect("dbname","" ,"");
From there, working with the database is pretty similar to MySQL as long as you use the ODBC functions.
The only problem is creating the actual MDB. This cannot be done in ODBC, you'll need the JET engine. It may be possible to create an MDB file from PHP, but it may be easier to create an empty MDB once, and copy that file from PHP whenever you need a new database.
Jackcess is a pure Java library for reading from and writing to MS Access databases. It is part of the OpenHMS project from Health Market Science, Inc. . It is not an application. There is no GUI. It's a library, intended for other developers to use to build Java applications.
http://jackcess.sourceforge.net/
But an MDF file is not a standard Access file extension. MDB and MDE are while MDW is for user level security.
Have not tested this but this might help you:
http://devzone.zend.com/article/4065
Note that active development of MDB Tools has moved from Sourceforge to Github
https://github.com/brianb/mdbtools
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database. But all the query work is done on the client side, I'd like to move some of this to PHP.
What driver and/or connection string is needed to connect to Sql Svr and what is the syntax to use in PHP?
Update: OK so I was definitely trying to avoid using anything to do with copying DLLs etc. I'll look into the SQL2K5PHP driver (thanks Vincent). #jcarrascal for the sake of clarity, by "client side" I mean our application is an internal web app that runs as an HTA, with all queries done via javascript calls to an ASP which actually submits the DB request.
You have two options:
1) php_mssql extension : If you'd like something that has the same API mysql and mysqli has, then use the php_mssql extension. But there is a catch, the bundled ntwdblib.dll file with PHP is not working. You have to find this file from a SQL Server 2000 installation or you can find it on the Internet. This API is supposedly not very reliable but I have been using it without problem for about one year.
http://ca.php.net/mssql
2) Microsoft SQL Server 2005 PHP Driver : If you'd like something more modern but which does not have the same API and is missing some important functions (mssql_num_rows). The big plus is that it is supported by Microsoft and is likely to work with a future version.
http://msdn.microsoft.com/en-us/data/cc299381.aspx
Just use the mssql_connect() function like this:
$conn = mssql_connect('localhost', 'sa' , '123456')
or die('Can\'t connect.');
mssql_select_db('database', $conn)
or die('Can\'t select the database');
Functions relating to SQL Server are defined in the PHP manual for the MSSQL driver.
One question though, "all the query work is done on the client side" WTF? :D
PHP provides an extension for accessing Microsoft SQL Server databases. To use the SQL Server extension, all that is required is to activate the extension in the PHP configuration file.
Details on the MSDN page