I am trying to connect to a Microsoft Access Database using PHP PDO, but got this error message:
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver
Manager]Data source name not found, and no default driver specified
The error happens at this line:
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};Dbq=C:\\wamp\\www\\phprestsql\\UTILITY.accdb");
I do not have an user name setup for the database, I also tried
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};Dbq=C:\\wamp\\www\\phprestsql\\UTILITY.accdb;User=Admin");
and the problem still remains
What could be the problem? I checked the path for the Access Database file and it is correct.
I am using the WAMP for the PHP.
The system is Windows 7 Home Premium. Do I need to install some ODBC driver?
Edit:
I downloaded the ACE according to HansUp's suggestion, but still has the same problem.
I have also tried to convert my file to .mdb, but still has the same problem. In the PHP code I verified the ,mdb file does exist. So it must be some kind of environment issue.
Update
Forgot to mention that I was running Virtual Box on Mac. Perhaps that was the problem.
Got really frustrated, then moved on to an old Windows Vista 32 bit machine and setup the environment using all 32 bit tools. It worked in the first run.
Thanks
Ray
Related
I trying to connect to an SQL Server in PHP. With XAMPP on my local machine, everything works well. But now I going to bring my application on the production server.
On this server there is installed the Microsoft IIS 6.1 and running the PHP version 7.0.7. I also installed the ODBC Driver from here. Next I decomment the following line in my php.ini file:
extension=php_sqlsrv_7_nts.dll
extension=php_pdo_sqlsrv_7_nts.dll
I got the files from the official microsoft site.
What's my problem?
Unfortunately, after I restarted the IIS. The PDO function throws the PDOException error with the following message:
could not find driver
For the connection I am using the following function which works pretty well on my local machine:
try {
$con = new PDO("sqlsrv:Server=" . SERVER . ";Database=" . DATABASE, USERNAME, PASSWORD);
// set the PDO error mode to exception
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "No connection: " . $e->getMessage();
exit;
}
What can I else do?
Here is detailed process if it's helpful for someone. PHP Version - 7.4
Download and extract the .dll files from this link - https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
Paste the files in C:\xampp\php\ext, your path could be different.
in php.ini add those two lines at bottom or in extension section.
extension=php_sqlsrv_74_ts_x64.dll
extension=php_pdo_sqlsrv_74_ts_x64.dll
Restart your Xampp server, I'll suggest restart your computer and everything will work without an issue then.
Check if SqlSRV enabled
Check using phpinfo() or http://localhost/dashboard/phpinfo.php at like this -
Hope, it will help someone.
After I found the error log on the Windows Server, I solved the error by myself.
I got this error in my log:
[21-Apr-2017 07:12:14 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '...\ext\php_pdo_sqlsrv_7_nts.dll' - %1 is not a valid Win32 application. in Unknown on line 0
Then I downloaded again the driver and installed the x64-Driver. Finally It works without any problems.
please notice you must use the correct version of php_sqlsrv_xx_xts_xxx.dll and php_pdo_sqlsrv_xx_xts_xx.dll files.
for exmple if you use php version 7.4 and a 64 bit system and wamp you must download and use these files:
php_sqlsrv_74_ts_x64.dll
php_pdo_sqlsrv_74_ts_x64.dll
for download you can use this site:
https://go.microsoft.com/fwlink/?linkid=2152937
https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
It took some time for me to solve the 'No driver'-error. I went through some steps as mentioned here and found some other ones that helped me after new errors. For future references:
Download the latest drivers from Microsoft (as said by Julian Schmuckli).
Check if your XAMPP is 64 bits(!) with Phpinfo(). If you've got 32-bit, you need different drivers.
Add the drivers to your Php.ini file and save the dll's in your php/ext-folder (question of saber tabatabaee yazdi).
For the connection, use this code:
$dbh = new PDO ("sqlsrv:Server=$server;Database=$dbname",$username,$pw);
If you add a port, use:
$server = "192.168.1.15, 51022";
Where the IP (can be hostname to) is your server and 51022 your port.
I cannot access the ODBC Driver. I have a 64 bit Windows 7 System. To connect to a ODBC 5.1 Driver I used C:\Windows\SysWOW64\odbcad32. I created a User DSN with name AJOY. There was no problem with that. Everything worked fine for the past 3 months. But now when I use
odbc_connect()
to connect with the same User DSN name i have a problem. I usually connect by the statement
$conn=odbc_connect("Ajoy","","");
There was no problem with the statement earlier. But now When I run my code it returns like
odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect
When I check the Data Sources (ODBC) in control panel, I can see the User DSN that I created but I cannot remove it. When i click remove it throws an error like
The setup routines for the MySQL 5.1 Driver ODBC could not be found. Please re-install the driver
It also returns there is an architecture mismatch between the driver and the application. I tried various steps but still it is not working. How to fix this? Help me please!!
I believe your problem is what odbcad32 you are using. You must use the one in the c:\Windows\System32 for a 64 bit application; not the c:\windows\SysWow64 directory.
There are 2 versions, one for 32 bit and one for 64 bit applications.
I have got FreeTDS, unixODBC and ODBC enabled on PHP. It all seems to work great. I could connect via iSQL command line.
For some reason PHP is not able to work when accessed via HTTP.
For example.
via command line if I run php index.php (where index.php connects via ODBC) it works well.
but the same code when accessed via HTTP, returns
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect
Could this be a case of some permission
Thanks in advance
Here is the connection code
$connect = odbc_connect("DSNNAME", "USERNAME", "PASSWORD") or die('e');
I have changed the credentials. But the code works fine when I run it via PHP command through SSH via Terminal. But when I run it through HTTP it does not.
Also on SSH I am NOT running it via root user. I am using ec2 AWS - and ran SSH via ec2-user (which is the default)
I feel 'apache' user does not have permission to something which I am unaware of.
You can add the DSN from the PHP source code like this
$dsn = "Driver=FreeTDS;Server=192.168.1.17;Port=1433;Database=mydb;TDS_Version=7.2;";
$Connection = odbc_connect($dsn,$user,$pass);
2021 - BACK TO THE FUTURE:
I know that this post is old, but my reply can point a desperate soul in the right direction:
You are using odbc and the command "isql" works just fine
You are using FreeTDS and the command "tsql" works just fine
Trouble is running the php scripts that have calls to odbc via FreeTDS -> keeps giving errors
Kindly read:
https://www.linuxquestions.org/questions/blog/tix-592494/freettds-libiodbc-iodbc-php-7-4-21-on-slackware-current-5-13-5-38621/
I am using Xampp on Windows 8 64 bit and using Oracle 11g Express Edition Command line.
I did uncomment oci8 extension on php.ini files restart Apache n i am using correct password my php code is
<?php
$conn = oci_connect('system','asd','locahost/XE');
?>
but i am getting this error
ORA-12154: TNS:could not resolve the connect identifier specified in C:\xampp\htdocs\am\index.php on line 2
but on other pc with windows 7 its working correctly.
My command line sql is running perfectly but php connection is not establishing.
Note:
when i was installing oracle on this pc (win8) i got an error as
The installer is unable to instantiate the file C:\Users\McLAUGH~1\AppData\Local\Temp{078E83D7-3FCC-4A72-903B-995C7CE44681}\KEY_XE.reg. The file does not appear to exist.
but i did press ok n everything seems to be fine but now this problem is happening please help me. Thanks
For the error you mentioned, please go throught the following link and follow the steps mentioned in it and try if your issue get resolved.
http://blog.mclaughlinsoftware.com/tag/install-oracle-11g-release-xe/
I'm new in sql anywhere, currently I'm trying to connect using PHP.
This is what I've got so far:
$conn = sqlanywhere_connect ( "UID=usr;PWD=pass;ENG=serv;DBN=bd_name;COMMLINKS=TCPIP{HOST=10.1.1.189:2638}" );
SQL Anywhere is installed on another machine, where I can't run apache, website is running on localhost (xampp). This is only for test, when website would be ready I will connect to correct db.
This is error I've got:
Warning: sqlanywhere_connect(): The SQLAnywhere client libraries could not be loaded. Please ensure that dbcapi.dll can be found in your PATH environment variable. in C:\xampp\htdocs\core\cache\includes\elements\modsnippet\25.include.cache.php on line 21
I haven't got dbcapi.dll file, but I'm not sure I should have it.
In documentation I couldnt find this file (SQL Anywhere 10 which I've got), but for SQL Anywhere 11 I could find pages where was info about this file.
To use sqlanywhere_connect I've download SQL Anywhere module for curren ver. of PHP onto my machine and I've add it to php.ini file.
What should I do? Should I download missing file? Would it be enough or I could get more errors asking for other files?
I had a similar problem and the solution proposed here:
https://groups.google.com/forum/#!msg/sql-anywhere-web-development/zK9Tf-X3cYk/GAoqK2DnB9EJ
worked for me.
Specifically, my xampp + php needed the 32 bit dbcapi.dll but when I installed SQL Anywhere 12 I neglected to check the box to install the 32 bit version as well. Re-installing, chossing "modify" and installing the 32 bit SQL Anywhere 12 got "php test.php" working.
I would down load the missing file and go from there you are using xamp which is pre-built to talk to mySQl I doubt there is any extra .dll in the Instillation to connect with SQLAnywhere