Question

I'm aware that there are lots of questions related to this one, but I didn't found an answer to my problem, I'm using Laravel 4 and I absolutelly must use MS SQL SERVER 2000. On Windows Server 2000, I'm using PHP 5.4.X or greater. I have found that MS doesn't offer support for mssql 2000 and I have solved the problem with the ODBC Driver, BUT my question is: Is there any way for me to tell Laravel to use the odbc driver without extensive configuration? or should I make my own implementation?

In the config/database.php the fetch uses PDO::FETCH_CLASS, but odbc is not PDO, Although in the PHP Manual there is an ODBC and DB2 (PDO) ... any thoughts?

Était-ce utile?

La solution

I solved it by making my own implementation using the PDO ODBC Driver and adding my classes to the composer.json in order to use them anywhere

<?php

class SqlServerPdo {

    private static $dbName = 'dbName' ;
    private static $dbHost = '127.0.0.1';
    private static $dbUsername = 'username';
    private static $dbUserPassword = 'password';

    private static $conn  = null;

    public function __construct() {
        die('Init function is not allowed');
    }

    public static function connect() {
       // One connection through whole application
        if ( null == self::$conn ) {     
          try {

                   self::$conn = new PDO("odbc:Driver={SQL Server};Server=SERVER-NAME;Database=" . self::$dbName . ";User Id=" . self::$dbUsername . ";Password=" . self::$dbUserPassword . ";");

          } catch(PDOException $e) {

              die($e->getMessage());

          }
       }

       return self::$conn;

    }

    public static function disconnect() {

        self::$conn = null;

    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top