yiisoft/db-mssql
Microsoft SQL Server driver for Yii Database. Adds MSSQL support to Yii’s DB layer, including PDO connections, schema introspection, query building, and command execution for database-backed PHP applications.
yiisoft/db-mssql is the MSSQL driver for the Yii DB abstraction layer — it is not a Laravel package, so treat it as a standalone PDO/query-builder you install via Composer alongside yiisoft/db. The 2.0.0 release is a hard reset: it targets PHP 8.1 – 8.5 and a matching yiisoft/db version, so confirm both are aligned before touching anything else.
composer require yiisoft/db-mssql:^2.0 yiisoft/db:^2.0 (the package now advertises a yiisoft/db-implementation virtual package, which lets other packages depend on "some driver" rather than this one specifically).Dsn and Connection:
$connection = new \Yiisoft\Db\Mssql\Connection(
new \Yiisoft\Db\Mssql\Driver\PDODriver(
new \Yiisoft\Db\Mssql\Dsn('sqlsrv', 'host', 'dbname'),
'user', 'password',
),
);
$connection->getSchema()->getTableSchema('users') now returns typed ColumnInterface instances (DateTimeColumn, JSON columns, enum columns, etc.) instead of generic schema objects — that is the headline 2.0 change and the thing to verify first on your schema.Column-typed schema. Every column now comes back as a ColumnInterface implementation matching its SQL Server data type, produced by ColumnFactory. When you build tooling that migrates, diffs, or generates models from SQL Server, branch on column class (DateTimeColumn, JSON column, enum column) rather than re-parsing type strings yourself.
Column/index definition builders. ColumnBuilder, ColumnDefinitionBuilder, IndexType, and IndexMethod mean you can programmatically compose DDL — table column SQL and index definitions — without stringly-typed fragments. These are the right hook points for a custom migration or fixture generator.
Expression helpers. ArrayMergeBuilder, GreatestBuilder, LeastBuilder, LengthBuilder, LongestBuilder, ShortestBuilder map to T-SQL functions. Use them through the DML/expression layer rather than raw SQL so parameter binding and quoting stay correct.
Returning-rows workflow. DMLQueryBuilder::insertReturningPks() (renamed from insertWithReturningPks()) is your pattern for inserting and getting keys back — Command::insertWithReturningPks() now returns array|false, so null-check explicitly. There is also upsertReturning() for upsert-then-read workflows. This is the closest MSSQL equivalent to Laravel's insertGetId + upsert.
Schema caching. getCacheKey()/getCacheTag() are gone from Schema — if you had custom caching wired to them, move the cache key/tag derivation into your own layer.
Case-sensitive LIKE. like conditions accept a new caseSensitive option — useful when SQL Server collation is CI but you need an exact-case match.
DDL with existence checks. dropTable() now takes $ifExists and $cascade, so idempotent teardown scripts can drop directly instead of querying metadata first.
ColumnSchemaInterface → ColumnInterface (and the old ColumnInterface was deleted), DMLQueryBuilder::insertWithReturningPks() → insertReturningPks(), Quoter::getTableNameParts() lost $withColumn, expression namespaces moved (#398), and QueryBuilder/Dsn constructors changed. Grep your codebase for these before upgrading.\InvalidArgumentException (plain PHP) instead of Yiisoft\Db\Exception\InvalidArgumentException. Catch blocks and tests asserting on the Yii class will break.#413 makes this an explicit exception instead of silent coercion. Audit any shared schema definitions across DBMSes.#343) — if you extend or override command/query-builder interfaces, match the signatures or PHP will complain.#380, #308). Schema-qualified names need the new quoting path; test anything like [dbo].[users].Schema::loadResultColumn() now understands identity (#408/#409) — if you generate inserts from introspected schemas, make sure identity columns aren't being written to.#360). If you relied on the old (incorrect) ordering, expect order changes.Connection::createBatchQueryResult() was removed — large result iteration must now go through the standard query-result path or your own chunking.#420 adds a "source of column information", which is the fastest way to know whether a column's type came from the catalog, a cached schema, or a fallback. Use it before assuming ColumnFactory mis-typed something.#418) — a fix, but worth re-checking any fixture snapshots of generated DDL.getColumnBuilderClass() (#391) is your extension point if you need a custom column builder; subclass the connection and override it rather than monkey-patching ColumnFactory.How can I help you explore Laravel packages today?