适用于 Windows 的 PHP 7.0 ODBC 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34200997/
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
PHP 7.0 ODBC-Driver for Windows
提问by user2077480
I upgraded my PHP 5.6.30 (https://www.apachefriends.org/de/download.html) to PHP 7.0 (https://bitnami.com/stack/wamp/installer)
我将 PHP 5.6.30 ( https://www.apachefriends.org/de/download.html)升级到 PHP 7.0 ( https://bitnami.com/stack/wamp/installer)
Everything worked fine so far and it reduces the loading time from my Page from 1,2 seconds to ~300 ms, when I use a MySQL-Database. But now I'm trying to connect to a MSSQL-Database with the following simple script, that worked fine with my old installation (PHP 5.6):
到目前为止一切正常,当我使用 MySQL 数据库时,它将我的页面的加载时间从 1.2 秒减少到约 300 毫秒。但是现在我正在尝试使用以下简单脚本连接到 MSSQL 数据库,该脚本在我的旧安装(PHP 5.6)中运行良好:
<?php
//Use the machine name and instance if multiple instances are used
$server = 'Server-Adress';
$user = '';
$pass = '';
//Define Port
$port='Port=1433';
$database = 'Databasename';
$connection_string = "DRIVER={SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
if ($conn) {
echo "Connection established.";
} else{
die("Connection could not be established.");
}
$sql = "SELECT * FROM st3_200 WHERE identifier = 1";
$result = odbc_exec($conn,$sql);
// Get Data From Result
while ($data[] = odbc_fetch_array($result));
// Free Result
odbc_free_result($result);
// Close Connection
odbc_close($conn);
// Show data
print_r($data);
?>
But now I got an error in my logs that says:
但是现在我的日志中有一个错误,上面写着:
[Thu Dec 10 11:55:26.629956 2015] [:error] [pid 260:tid 968] [client ::1:63003] PHP Fatal error: Uncaught Error: Call to undefined function odbc_connect() in C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs\test\query.php:11\nStack trace:\n#0 {main}\n thrown in C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs\test\query.php on line 11
[Thu Dec 10 11:55:26.629956 2015] [:error] [pid 260:tid 968] [client ::1:63003] PHP 致命错误:未捕获错误:调用 C:\Bitnami\ 中未定义的函数 odbc_connect() wampstack-7.0.0-0\apache2\htdocs\test\query.php:11\nStack trace:\n#0 {main}\n 抛出在 C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs \test\query.php 第 11 行
First I thought, that my php.ini has a missing extension, so I enabled "extension=php_pdo_odbc.dll"
首先我想,我的 php.ini 缺少扩展名,所以我启用了“extension=php_pdo_odbc.dll”
the difference from the php.ini in the 5.6 version is there is the extension: "extension=php_mssql.dll" enabled. But I can't find them in the new PHP 7.0.ini
与 5.6 版本中的 php.ini 的不同之处在于启用了扩展名:“extension=php_mssql.dll”。但是我在新的 PHP 7.0.ini 中找不到它们
So my intension is there is no existing driver for odbc and PHP 7 yet? I found some driver for Linux here: https://aur.archlinux.org/packages/php7-odbc/
所以我的意图是 odbc 和 PHP 7 还没有现有的驱动程序吗?我在这里找到了一些 Linux 驱动程序:https: //aur.archlinux.org/packages/php7-odbc/
But I need something for my Windows environment.
但是我需要一些适合我的 Windows 环境的东西。
Does anyone had the same issue and has already fixed it?
有没有人遇到过同样的问题并且已经解决了?
Thank und Greeting Domi
感谢和问候 Domi
回答by fweber
Take a look in your php.ini, the string
看看你的 php.ini,字符串
extension=php_odbc.dll
seems to be missing in new installations, at least i had to add it manually in my new XAMPP installation (7.0.1) and accidently just activated the pdo_odbc.dll
似乎在新安装中丢失了,至少我必须在我的新 XAMPP 安装(7.0.1)中手动添加它,并且不小心激活了 pdo_odbc.dll
回答by Tim Penner
PHP7has a few modules disabled by default that were previously enabled in PHP5.
PHP7默认情况下禁用了一些先前在PHP5.
It's an easy fix though since the extension should already exist in the \ext\
folder that came with PHP7. You just need to modify your php.ini
file to include the line:
这是一个简单的办法,虽然由于延伸应该在已经存在\ext\
,随着来了文件夹PHP7。您只需要修改您的php.ini
文件以包含以下行:
extension=php_odbc.dll
The line above is notalready present and commented out; you actually need to add it!
上面的线是不已经存在和注释; 你实际上需要添加它!
PHP looks for the php.ini
file in C:\Windows\
but it may also be located elsewhere on your machine. So check both C:\Windows\
and C:\php\
or where ever else you may have installed PHP.
PHP 会在其中查找该php.ini
文件,C:\Windows\
但它也可能位于您机器上的其他位置。因此,检查既C:\Windows\
和C:\php\
,或者你可能已经安装了别的地方过PHP。
After making the change you can check the results from the command line like this:
进行更改后,您可以从命令行检查结果,如下所示:
C:\php\php.exe -m
or (after restarting the web server / machine) from a .phtml
file like this:
或(在重新启动 Web 服务器/机器后)从这样的.phtml
文件:
<? phpinfo(); ?>
That will output a list of enabled modules which should now include odbc; if not, then you may have modified the wrong php.ini
file (keep looking) or forgot to restart the web server / machine.
这将输出一个启用模块的列表,现在应该包括odbc:如果没有,那么您可能修改了错误的php.ini
文件(继续查找)或忘记重新启动 Web 服务器/机器。
Tips:
提示:
If you have a non-standard installation, you can use an absolute path like this:
如果你有一个非标准安装,你可以使用这样的绝对路径:
extension=C:\php7x64\ext\php_odbc.dll
回答by Adrian B
extension=php_mssql.dll (or extension=php_sqlsrv_56_nts.dll if you get it from Microsoft Drivers for PHP), is your problem: the Microsoft SQL driver for PHP 7 is not yet ready, the latest ETA is late January for the beta.
extension=php_mssql.dll(或 extension=php_sqlsrv_56_nts.dll,如果您从 Microsoft Drivers for PHP 获得),是您的问题:用于 PHP 7 的 Microsoft SQL 驱动程序尚未准备好,最新的 ETA 是测试版的 1 月下旬。
It looks like the cause of the delay is the intention to include SQL 2016 in that driver so you can migrate easier in the future.
看起来延迟的原因是打算在该驱动程序中包含 SQL 2016,以便您将来可以更轻松地迁移。
UPDATE (2016/02/12):
更新(2016/02/12):
As stated here(meet-bhagdev reply), there is an "early technical preview" of the PHP sqlsrv driver for Windows available on github.
如前所述这里(聚会bhagdev回复),还有就是PHP SQLSRV驱动程序适用于Windows的“早期技术预览版”上可用github上。
回答by Jhollman Cutcsa
Open your php.ini file and uncomment or add the following lines:
打开您的 php.ini 文件并取消注释或添加以下行:
extension_dir = "C:\PHP\ext" ;<- your PHP path
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Reset Internet Information Services: On command prompt with admin rights type:
重置 Internet 信息服务:在具有管理员权限的命令提示符下键入:
iisreset
This fixed the problem for me.
这为我解决了问题。
回答by Naio
We need x86 driver from Microsoft. http://www.microsoft.com/ja-jp/download/details.aspx?id=13255*Sorry, 'ja-jp' is mine. Please select your country. There are 2 drivers, one is 32bit, but we need 64bit(x86) version. Then we could set "ODBC data source (64bit)". It appears on the window. Last, check your web. Maybe it works. Mar. 29th. 2016 Naio
我们需要微软的 x86 驱动程序。 http://www.microsoft.com/ja-jp/download/details.aspx?id=13255*抱歉,“ja-jp”是我的。请选择你的国家。有 2 个驱动程序,一个是 32bit,但我们需要 64bit(x86) 版本。然后我们可以设置“ODBC数据源(64位)”。它出现在窗口上。最后,检查您的网络。也许它有效。3 月 29 日。2016 奈欧
回答by Akin Ocal
As an addition to Adrian B`s which mentions the official driver, you can also check https://github.com/thomsonreuters/msphpsqlThis is an unofficial port. However there are limitations for the time being.
作为Adrian B`s 提到官方驱动的补充,你还可以查看https://github.com/thomsonreuters/msphpsql这是一个非官方的端口。不过暂时还是有限制的。
- Supports only sqlsrv ODBC but not PDO
- Doesn`t support ZTS, only NTS
- Supports only x86
- It supports a subset of ODBC functions , you can see the list on the page.
- 仅支持 sqlsrv ODBC 但不支持 PDO
- 不支持ZTS,只支持NTS
- 仅支持 x86
- 它支持 ODBC 函数的一个子集,您可以在页面上查看列表。
回答by Nikolay Yenbakhtov
I guess you was right, you need download the SQL Server ODBC driver for your PHP client platform and OS.
Here is the link for the similar issue: Call to undefined function odbc_connect()
我猜你是对的,你需要为你的 PHP 客户端平台和操作系统下载 SQL Server ODBC 驱动程序。
这是类似问题的链接:Call to undefined function odbc_connect()
also you can try to install this connector for MySQL (if you use MySQL): Connector/ODBC
您也可以尝试为 MySQL 安装此连接器(如果您使用 MySQL):Connector/ODBC
or if you use MSSQL: ODBC Driver 11 for SQL Server
或者如果您使用 MSSQL:用于 SQL Server 的 ODBC 驱动程序 11
回答by Cédric Fran?oys
I know this question is rather old. But I've come across the same issue recently ...
我知道这个问题已经很老了。但是我最近遇到了同样的问题......
@Naio is right : there are indeed different versions of ODBC drivers, based on the architecture (32bits or 64bits). The driver that PHP uses depends on its own version.
@Naio 是对的:确实有不同版本的 ODBC 驱动程序,基于架构(32 位或 64 位)。PHP 使用的驱动程序取决于它自己的版本。
In other words, if you are using a 32bits ODBC environement, make sure to use a 32bits version of PHP ...
换句话说,如果您使用的是 32 位 ODBC 环境,请确保使用 32 位版本的 PHP ...
My guess is that, by switching from PHP 5.6 to PHP 7.0 you also switched from a 32bits version to a 64bits version.
我的猜测是,通过从 PHP 5.6 切换到 PHP 7.0,您也会从 32 位版本切换到 64 位版本。