php 如何更正此错误:未找到数据源名称且未指定默认驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9122611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I correct this error: Data source name not found and no default driver specified
提问by prukuhkoo
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:
我有一个在 Windows 服务器上运行的网站,它运行得非常好。我试图在我的本地主机中制作一个副本,但出现错误:
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:
第 29 行包含:
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
我真的是 odbc 的新手。该网站是用php和我在mySQL中使用的数据库编写的。虽然我认为它试图连接的数据库是一个 microsoft access MDE 文件。(我在 Windows 服务器中检查了该站点。)我该怎么办?我很抱歉,但我真的
回答by user2690047
It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.
设置 ODBC 数据源的快捷方式很可能指向 32 位数据源而不是 64 位。
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
转到控制面板-> 管理工具--> 选择数据源(ODBC)--> 然后右键单击该文件--> 转到属性--> 在快捷方式选项卡中-> 更改路径
%windir%\System32\odbcad32.exe
to
到
%windir%\SysWOW64\odbcad32.exe
and make your connection. the driver for MS Access will work fine now.
并建立联系。MS Access 的驱动程序现在可以正常工作。
If it doesnt work, try to connect to the ODBC with a sentence like this:
如果它不起作用,请尝试使用如下语句连接到 ODBC:
$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
如果您没有任何用户名或密码,则最后 2 个离开然后只是 ''
回答by Tomi
I was getting the same error on PHP 7.0.8 64bit while trying to connect to an Access .mdb.
在尝试连接到 Access .mdb 时,我在 PHP 7.0.8 64 位上遇到了同样的错误。
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)}
安装 64 位版本的“Microsoft Access Database Engine 2010 Redistributable”(即使安装了 Access 2016,我也收到了您的错误)。您可以从以下位置下载驱动程序:
https://www.microsoft.com/en-us/download/details.aspx?id=13255
然后,如果您转到 ODBC 数据源管理器,您应该注意到 64 位版本。
将驱动程序字符串更改为:
Driver={Microsoft Access Driver (*.mdb, *.accdb)}
Hope it helps other people.
希望它可以帮助其他人。