Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\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

like image 997
user2077480 Avatar asked Dec 10 '15 11:12

user2077480


People also ask

How enable Sqlsrv in PHP INI?

The SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php. ini file. The SQLSRV download comes with 8 driver files, four of which are for PDO support. The most recent version of the driver is available for download here: » SQLSRV download.


1 Answers

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

like image 175
fweber Avatar answered Sep 21 '22 07:09

fweber