Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Db Mssql Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

  1. 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).
  2. Build a 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',
        ),
    );
    
  3. First use case: schema introspection. $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.

Implementation Patterns

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.

Gotchas and Tips

  • This is a breaking release; upgrade will hurt. Notable renames/removals: 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.
  • Exceptions moved. The package now throws \InvalidArgumentException (plain PHP) instead of Yiisoft\Db\Exception\InvalidArgumentException. Catch blocks and tests asserting on the Yii class will break.
  • Unsigned columns now throw. SQL Server has no unsigned types; #413 makes this an explicit exception instead of silent coercion. Audit any shared schema definitions across DBMSes.
  • Nullable parameters are now explicit (#343) — if you extend or override command/query-builder interfaces, match the signatures or PHP will complain.
  • Table names with dots are no longer supported in the way they were (#380, #308). Schema-qualified names need the new quoting path; test anything like [dbo].[users].
  • Identity columns: Schema::loadResultColumn() now understands identity (#408/#409) — if you generate inserts from introspected schemas, make sure identity columns aren't being written to.
  • Composite primary key column order was fixed (#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.
  • Debugging schema issues: #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.
  • PHP 8.5 warnings: default-value normalization trims a leading dot on large numeric defaults (#418) — a fix, but worth re-checking any fixture snapshots of generated DDL.
  • Config quirks: getColumnBuilderClass() (#391) is your extension point if you need a custom column builder; subclass the connection and override it rather than monkey-patching ColumnFactory.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle