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.
Related
I have linked SQL Server into Active Directory and am trying to use PHP to create an ODBC connection to pull in the data. I can read from Active Directory fine but when I try and update it using SQL UPDATE, I get this error
Msg 7390, Level 16, State 2, Line 1
The requested operation could not be performed because OLE DB provider "ADSDSOObject" for linked server "ADSI" does not support the required transaction interface.
I know I have to use PHP's LDAP functions but I am not sure how to rewrite the LDAP string to use in PHP. My best guess would be:
I tried (example string):
OU=staff,DC=example,DC=internal
but this doesn't work. My question is: assuming there is no way of updating Active Directory from my SQL view, how do I go about updating LDAP with PHP?
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.
I have Access 2007 installed and I downloaded the Northwind Traders sample database which is easily available on the Internet.
I want to open connection with this database in PHP so that I can practice my PHP coding. I want to directly access the database without having to export it to MySQL and then accessing it.
I followed the following steps from http://www.w3schools.com/php/php_db_odbc.asp to achive that:
Open the Administrative Tools icon in your Control Panel.
Double-click on the Data Sources (ODBC) icon inside.
Choose the System DSN tab.
Click on Add in the System DSN tab.
Select the Microsoft Access Driver. Click Finish.
In the next screen, click Select to locate the database.
Give the database a Data Source Name (DSN).
Click OK.
Then I tried the following code in php :
<?php
$conn=odbc_connect('northwind','','');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
?>
But it is displaying "Connection Failed".
Please advise me how I can connect to Northwind database directly.
I have Microsoft Access Database (mdb file) with a table in it (we'll call that table A) that is linked to another Microsoft Access Database (we'll call that table B). I need to be able to update table A using php (which will in turn update table B, since A is linked to B). Please note that the table I'm linking to has a primary key named "Intersection" and it is set to Indexed: Yes (No duplicates).
If I use a simple odbc_connect and odbc_exec to run the following query:
$con= odbc_connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$mdbFilename", $user, $password)
$res = odbc_exec($con, "UPDATE tableA SET myfield=NULL WHERE myfield=2439;");
However, when I try this on a database with a linked table, I get the following error:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC
Microsoft Access Driver] Operation must use an updateable query., SQL
state S1000 in SQLExecDirect in G:\web\libs\test.php on line 413
For some reason it seems that my database is not updateable even though it should be. It has a primary key defined and is a simple table (except for the fact that it's linked). Originally I was getting the following error:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC
Microsoft Access Driver] 'H:\test\Database\test.mdb' is not a valid
path. Make sure that the path name is spelled correctly and that you
are connected to the server on which the file resides., SQL state
S1009 in SQLExecDirect in G:\web\libs\test.php on line 413
But then I changed my linked table so instead of using drive letters to navigate to the linked table, I used the absolute \server\ path, which seemed to fix that problem, however not it is not able to be updated.
In case it helps, to create the Linked table, all I did was (Using MS Access 2010) I hit the "External Data" tab, then the "Access" (button), then I made sure to hit "Link to the source by creating a linked table" (option) and I selected the other database which contains the original table.
Is there some way to run an update on a linked access table using php?
Again, if you have a MS Access linked table that is linked to another table, and these tables have a primary key that is properly indexed. You CANNOT update the table using the following above PHP code (even though it works completely fine on an table which is not linked).
Please note, I have tested this with a fresh accdb database file as well, and if it is a linked table, it seems it will become read-only if you try to update the table using odbc_exec, however it does return data just fine, I just can't insert or update records.
Thank you.
[UPDATE]
Our server is running Windows Server 2003 with apache, and php. So I set up a Windows 7 machine with apache, and php, and it IS able to update a linked database without a problem, so I suspect my problem (since it's the only difference between the machines that could affect this), is that the Win2003 server is running odbc v3.5 whereas my win7 Machine is running odbc v6.1. I'm still looking into this further and will update this post if I find a solution to getting it working on our Windows Server 2003 machine.
I have a website that runs in Windows server, and it works perfectly fine. I tried to make a copy in my localhost but I get the error:
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\xampp\htdocs\tdms\webfolders\secured\db_fns.php on line 29
Could not connect to database server
line 29 contains:
function fgsdb_connect()
{
$a=array();
$retvar=0;
$result = odbc_connect('FGS','tdms','tdms358',SQL_CUR_USE_ODBC); //---->line 29
if (!$result) // cannot establish connection to database
throw new Exception('Could not connect to database server');
else // connection to database has been established
return $result;
}
I am really new to odbc. the website is written in php and the database that i use in mySQL. though i figured that the database that it is trying to connect is a microsoft access MDE file. (i checked in the site in windows server.) What should i do? im sorry but i am really
It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.
Go to control panel -> administrative tools --> select data sources(ODBC) --> then right click on that file --> go to properties --> in the shortcut tab -> change the path from
%windir%\System32\odbcad32.exe
to
%windir%\SysWOW64\odbcad32.exe
and make your connection. the driver for MS Access will work fine now.
If it doesnt work, try to connect to the ODBC with a sentence like this:
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\YourFolder\YourFile.mdb",'Youruser', 'YourPassword');
The last 2 leave then just the the '' if you dont have any user or password
I was getting the same error on PHP 7.0.8 64bit while trying to connect to an Access .mdb.
I had to do two things:
Install the 64bit version of "Microsoft Access Database Engine 2010 Redistributable" (even with Access 2016 installed I was getting your error). You can download the driver from:
https://www.microsoft.com/en-us/download/details.aspx?id=13255
Then, if you go to the ODBC Data Source Administrator, you should notice the 64bit version.
Change the driver string to:
Driver={Microsoft Access Driver (*.mdb, *.accdb)}
Hope it helps other people.