TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
KO3, ORM, and MSSQL
  • I have to port and refactor a large web app that was originally written in PERL, and uses MSSQL (unfortunately) for the backend. I've done several apps in KO2, and this is my first project using KO3. I see that KO3 is using PDO for everything except MySQL. Are there any limitations in KO3's support for MSSQL; e.g., do any of the database modeling systems (ORM, Sprig, Jelly) work with MSSQL? I've searched on the forums about this -- I've seen scattered mentions of MSSQL drivers, modules, extensions of PDO, etc., but I was unable to find a definitive info about the current state of support for MSSQL. Thanks!
  • http://github.com/xrado/kohana-mssql ..try it, test it ...uses pdo
    ORM works fine
  • ORM will not work with MSSQL, unless you specify the column names manually, because PDO does not support the "list columns" method.

    There was someone who started a MSSQL module for more robust handling of limit() and other things, search for forums for it.

  • Thanks guys. I'll check out xrado's module.

    @xrado
    Have you tried this with other modeling systems? Or do I need to stick with ORM?
  • no i didn't tried with other modeling systems, just ORM
    but the module provides all the needed method (also list columns)
    haven't tested it with complex queries jet
    let me know if you find any bugs/problems
  • Thanks, I will!
  • Many pieces of the ORM will not work out of the box with MSSQL because of differences in query structure. OFFSET is not supported and LIMIT is called TOP. These are pieces within the Query Builder that must be tweaked. Just today I found out there is a bug in the mssql and pdo_mssql plugins for Windows that shortens all VARCHARs to 255 characters so they must be cast as TEXT. I will see if I can get some of those pieces together for you.

    That being said, Kohana 3 is very customizable so you should be able to extend the Kohana version of the class, implement the required methods, and override the default ones.
  • All of that info is greatly appreciated, dcinited. I've never worked with MSSQL, so every little hint I can get is helpful. The DB itself is in someone else's hands, for better of worse. But I will definitely check into the data types and look out for any other "irregularities". Thankfully the queries I need for this app will be limited only (so far, anyway) to the display component of CRUD. but if I run into limits or offsets, at least I won't be surprised now. Thanks again.
  • Not working OFFSET with MSSQL 2000 (ROW_NUMBER() - not found)
  • is there any alternative to ROW_NUMBER() in MsSQL 2000?
  • I'm finally getting around to trying out this module, but I'm getting a "PDOException [ 0 ]: could not find driver" error. I have a database config file set up as in your readme example. And I have the two 'mssql.php' files located in modules/classes/kohana/database/ and modules/database/ respectively. Have I skipped/missed any steps?
  • don't touch anything in database module, just download kohana-mssql and add it to module folder as a separate folder.
    load modules like this

    'kohana-mssql' => MODPATH.'kohana-mssql',
    'database' => MODPATH.'database', // Database access
  • Thanks. I've done this and removed the two files that I had copied into modules as mentioned in my previous message. That at least gets me to a different error (below); does this provide any clues? And a related, perhaps dumb, question: have you used this on a *nix platform, and did you first have to recompile php with mssql and or/ pdo-dlib extensions?


    ErrorException [ Fatal Error ]: Class 'Database_Mssql' not found

    MODPATH/database/classes/kohana/database.php [ 52 ]

    47
    48 // Set the driver class name
    49 $driver = 'Database_'.ucfirst($config['type']);
    50
    51 // Create the database connection instance
    52 new $driver($name, $config);
    53 }
    54
    55 return Database::$instances[$name];
    56 }
    57

    1.

    {PHP internal call} » Kohana_Core::shutdown_handler()
  • otherwise I think a major refactoring should be made on the database module and query compilation should be moved into the adapters.
  • @buckthorn where did you put kohana-mssql ? yes i use it on ubuntu linux, requires php5-mssql and freetds packets, thats for pdo support. Native support requires recompiling i think.
  • @xrado I put the kohana-mssql directory inside the modules folder. It's at the root level of modules; the same level as "database". But regardless, I'm going to have to recompile php in order to get this to work. Thanks.
  • OK I got that first error resolved. Now I am getting:

    ERROR: PDOException [ 0 ]: could not find driver ~ MODPATH/database/classes/kohana/database/pdo.php [ 53 ]
  • @velkymx Sounds like your PHP installation does not have the MSSQL driver available.
  • Check first if the MSSQL driver is really working. I've once work a project using SQL Server 2005 and we have hard time to make the MSSQL driver working.

    It was a ZF project using PDO_MSSQL and I think I download a DLL for that on some site.

    PHP 5.2.6

    BTW if you're interested, I still have that DLL on my current machine.
  • @xrado - the new readme is most helpful! @shadowhand yes, seems xampp doesn't have it included.