Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

sql server - PHP 7.0 ODBC-Driver for Windows

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:Bitnamiwampstack-7.0.0-0apache2htdocsestquery.php:11 Stack trace: #0 {main} thrown in C:Bitnamiwampstack-7.0.0-0apache2htdocsestquery.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...