适用于Windows的PHP 7.0 ODBC-Driver [英] PHP 7.0 ODBC-Driver for Windows

查看:368
本文介绍了适用于Windows的PHP 7.0 ODBC-Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级了我的PHP 5.6.30( https://www.apachefriends.org/de/download.html )转换为PHP 7.0( https://bitnami.com/stack/wamp/installer )

到目前为止,一切正常,当我使用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);

?>

但是现在我的日志中出现错误,提示:

[2015年12月10日星期四11:55:26.629956] [:错误] [pid 260:tid 968] [客户端 ::: 1:63003] PHP致命错误:未捕获错误:调用未定义 函数odbc_connect()在 C:\ Bitnami \ wampstack-7.0.0-0 \ apache2 \ htdocs \ test \ query.php:11 \ nStack 跟踪:\ n#0 {main} \ n抛出 C:\ Bitnami \ wampstack-7.0.0-0 \ apache2 \ htdocs \ test \ query.php在 第11行

首先,我认为我的php.ini缺少扩展名,因此我启用了"extension = php_pdo_odbc.dll"

与5.6版本中的php.ini的不同之处在于存在扩展名: 启用"extension = php_mssql.dll".但是我在新的PHP 7.0.ini中找不到它们

所以我的意思是,尚无odbc和PHP 7的现有驱动程序? 我在这里找到了一些用于Linux的驱动程序: https://aur.archlinux.org/packages/php7-odbc/

但是我的Windows环境需要一些东西.

有人有相同的问题并且已经解决了吗?

感谢和问候 多米

解决方案

看看您的php.ini中的字符串

extension=php_odbc.dll

似乎在新安装中丢失,至少我必须在新的XAMPP安装(7.0.1)中手动添加它 并偶然激活了pdo_odbc.dll

I upgraded my PHP 5.6.30 (https://www.apachefriends.org/de/download.html) to 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):

<?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

First I thought, that my php.ini has a missing extension, so I enabled "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

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/

But I need something for my Windows environment.

Does anyone had the same issue and has already fixed it?

Thank und Greeting Domi

解决方案

Take a look in your php.ini, the string

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

这篇关于适用于Windows的PHP 7.0 ODBC-Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆