I am trying to use PHP's COM interface to query a database and create pivot tables from the data in an Excel Workbook.
I have configured the DCOM settings on the local machine to grant the user Local Access, Local Launch, and Local Activation privileges as well as Full Control of Configuration Permissions. I have also tried all three Identity settings.
Here is the code I am using:
<?php
$application = new COM("Excel.Application") or die("Unable to load Excel.");
$workbook = $application->Workbooks;
$workbook = $workbook->Add();
$sheet = $workbook->Worksheets(1);
$sheet->Activate();
$application->Quit();
?>
This is the error I am getting:
PHP Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `Workbooks': Access is denied.
This is different than error I was getting before which told me that I didn't have access to the Excel COM object. Setting the permissions fixed that.
Environment is:
Windows Server 2012 R2
Excel 2010 (64-bit)
PHP 5.5.9 (64-bit)
I never was able to solve this, so we had to come up with a different solution and it actually is more stable and performs better. Hope it helps anyone else that may run into the same issue.
Our database is MySQL (but this should be possible with most databases), so we moved our query into its own script and used the mysql client to write the results directly to a file.
We then created an excel template with a data connection to the file and used the connection as the data source for the pivot tables.
Lastly we wrote a short vbscript to open the template, refresh the pivot tables, then and save the file as a new copy.
This had the added benefit of allowing us to make stylistic changes using Excel's interface, which was much faster than doing it programmatically.
Related
I have figured out a strange problem with using PHP SQLite3 with Windows.
I have 2 different virtuell windows server. On the first one the SQLite3 database is located and on the second one the WEB-Server and PHP.
In the same PHP script there are different functions which require access to the SQLite3 database. These is the subroutine, which is use to open the SQLite database.
class SQLite extends SQLite3 {
function __construct() {
$this->open('//COUNTRYR/CountryR_driveD/Radio/database.mldb');
}
}
The strange thing is, that the call $db1 = new SQLite() is working for one function in this script but not for another. For the second function I always get the error message Fatal error: Uncaught Exception: Unable to open database: unable to open database file in ....
It took me some time, to figure out the difference.
The function which was able to open the database was called via php xyz.php --mode='abc' --user='test' --pass='1234' and the second function was called via a browser.
So the difference can only be different access rights in both cases.
For the PHP call of the function, the 'IUSR' has access rights for the database.
Due to the fact, that the server with the database is no Web server, I can not enable 'IIS_IUSRS' access rights for the database and I also don't want to give 'IIS_IUSRS' access rights to the database for security reasons.
Is there any other way to solve this problem?
Is 'IIS_IUSRS' the user which requires access for the WEB browser?
A bit about my current setup, The website is hosted on a windows server 2012 IIS with PHP 7.1, the site runs using Laravel with Medoo to load the database, however on any form of SQL statement the code fails with the error mentioned in the title.
Currently the file permissions are on Full Control for debug purposes
The code used for the call is the following
$pdo = new \Medoo\Medoo([
'database_type' => 'sqlite',
'database_file' => $config->database_path
]);
$query = $pdo->select('computers', '*');
I have tried making a SQL dump of the SQLite database file using a program called "DB Browser for SQLite" and the making a new database file from scatch then importing the SQL dump.
When this is done the program works without problem, so my current thought is there might be a limit on PDO SQLite file limit size since the original file is about 2.8MB while the new is 1.9MB
Is there anyone who have encounter a similar problem? or have any advice on how to fix the current problem?
I have a very simple SQLite database that I need to read/write to from a different server.
Say the database is stored here : http://www.abc.com/data/data.sqlite
And I'm using PHP to access it from http://www.xyz.com
So my first attempt was the following:
$dbpath = "http://www.abc.com/data/data.sqlite";
$dbconn = "sqlite:$dbpath";
$db = new PDO($dbconn)
No good, I get the following:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [14] unable to open database file'.........PDO->__construct('sqlite:http://w...') #1 {main} thrown
If try and copy the database onto the same server I'm accessing from:
$dbpath = "http://www.xyz.com/data/data.sqlite";
$dbconn = "sqlite:$dbpath";
$db = new PDO($dbconn)
I get the same message.
It's only when I give it a relative path on the same server:
$dbpath = "../data/data.sqlite";
That it actually works.
I know the database URLs and database itself are correct.
So is there a limitation to accessing cross-servers? Anyone know out to solve this issue?
Thanks a lot.
There are no such thing like 'SQLite server'. It exists only in a form of a file.
But there are no files in the HTTP protocol, but URIs only.
So, this is essential incompatibility.
To be able to do remote calls you have 3 choices
Only as a joke: download the file locally before each SELECT query and upload it back after updates
Establish some proxy script, to recieve a query and to return json.
Get yourself a real database server.
Or just change the project architecture to eliminate the need of remote access.
Because no one answer my question Codeigniter using ms access database , i make new question i not using codeigniter
if I using mdb from my computer it works but if i using mdb from another computer in my network
i got error this is my CODE
<?php
$connect = odbc_connect("testdb", "", "");
$query = "SELECT * FROM ACGroup";
$result = odbc_exec($connect, $query);
while(odbc_fetch_row($result)){
$name = odbc_result($result, 1);
echo("$name");
}
?>
i make odbc where the data its from another computer in my network
"testdb" are data sourcename and database \\ip\folder\testdb.mdb
and i got this error
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Microsoft Access Driver]
The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data.,
SQL state S1000 in SQLConnect in D:\blabla\coba.php on line 3
I already try folder setting but it not work
The ODBC connection string you are using ("testdb") does not even specify a database driver, much less a database file. You will need to read up on the appropriate format for $dsn. (The php.net page even has a few examples for Access files.)
The problem possibly lies in the permissions your Apache user has on the mdb file.
Go to your mdb file, right-clik on the file -> Properties ->Security tab and see if your Apache user is on the User Groups that have access/control on the mdb file.
In order to see/change your Apache user, go to Control Panel-> Administrative Tools -> Services, right-click on Apache service -> Properties -> Logon tab. In the Log on as option, see if the user selected belongs to the User Groups that have access to mdb file. If not, create one and add it to the User Groups and then use it as the Apache account.
I have used php5 to create a sqlite database. The database works fine when accessing its data using php.
However when I try and connect to the same sqlite file using firefox sqlite manager, I get the following error....
SQLiteManager: Error in opening file jTest.sqlite - either the file is
encrypted or corrupt Exception Name: NS_ERROR_FILE_CORRUPTED Exception
Message: Component returned failure code: 0x8052000b
(NS_ERROR_FILE_CORRUPTED) [mozIStorageService.openUnsharedDatabase]
My question:
Can you use php to create sqlite databases and have them work in other applications?
regards J