Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
sql server PDO
  • Hi I have a problem with sql server 2014
    this is my database config :
    return array(
        'default' => array(
            'type'         => 'pdo',
            'connection'   => array(
                'dsn'        => "sqlsrv:Server=localhost;Database=dbname",
                'hostname'   => '',
                'username'   => "username",
                'password'   => "password",
                'database'   => '',
                'persistent' => false,
                'compress'   => false,
            ),
            'identifier'   => '',
            'table_prefix' => '',
            'charset'      => 'utf8',
            'enable_cache' => true,
            'profiling'    => false,
        ),
    );

    error : Fuel\Core\Database_Exception [ 42000 ]:SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]'NAMES' is not a recognized SET option.

    error from file : classes/database/pdo/connection.php line 483 for $this->_config['attrs'] witch set in line 82:
    $this->_config['attrs'] = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION);

    by microsoft document :
    bool PDO::setAttribute ( $attribute, $value );


    and when i delete $this->_config['attrs'] like :
    $this->_connection = new \PDO(
    $this->_config['connection']['dsn'],
    $this->_config['connection']['username'],
    $this->_config['connection']['password']
    );
    it work correct!

    unfortunately, there is no possibility pagination on sqlsrv!
    as sql server 2012 microsoft add
    OFFSET and FETCH
    sample :

    SELECT field FROM table ORDER BY field [or(SELECT 0) for not order] OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY

    how can i check connection type in Database_Query_Builder_Select class ?
  • HarroHarro
    Accepted Answer
    The current PDO driver is a generic driver that only provides support for ANSI SQL. Unfortunately, MS-SQL is different.

    Fuel 1.8+ has a "sqlsrv" driver that should allow you to connect and use the list_tables() and list_columns() functions, but several people attempting to write MS-SQL query extensions have never contributed something back that worked.

    Fuel 1.8+ also allow you to create your custom query extensions and overload existing methods, you don't have to modify existing code. If you look at the SQLite driver, that comes with overloaded update and delete functionality.

    it gets more complex since different versions of MS-SQL require different solutions (there are at least 3 different solutions for the LIMIT/OFFSET problem), also PHP on Windows needs different drivers than PHP on Linux.

    All in all, quite a bit of work, and difficult since none of us has access to a Windows environment.
  • HarroHarro
    Accepted Answer
    You might want to check out http://fuelphp.com/forums/discussion/comment/20461 which has a discussion on how custom drivers work (it is about Informix, but the same applies for MSSQL).
  • hi Harro.
    Thank you for your answer.

  • hi Harro
    i finish change sqlsrv connection class and add select builder class.
    and work correct for sql server 2012 - 2016

    more help please :
    i cant find any sample for use stored procedure or function in fuelphp docs.
    my database full of function and stored procedure with input parameters and return result ;(
    how can i use DB class to work with that?(php docs)
    thank you again
  • HarroHarro
    Accepted Answer
    It's just SQL, so this should do it:

    $result = DB::query("EXEC dbo.someProcedure @var=123", DB::SELECT);

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion