PHPackages                             ai-zamurai/phalcon-sqlsrv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ai-zamurai/phalcon-sqlsrv

ActiveLibrary[Framework](/categories/framework)

ai-zamurai/phalcon-sqlsrv
=========================

Phalcon - MS SQL Server (PDO) Adapter (Phalcon 4 compatible fork)

v1.0.1(3mo ago)012[2 issues](https://github.com/ai-zamurai/phalcon-sqlsrv/issues)BSD-3-ClausePHPPHP &gt;=7.4

Since Apr 10Pushed 3mo agoCompare

[ Source](https://github.com/ai-zamurai/phalcon-sqlsrv)[ Packagist](https://packagist.org/packages/ai-zamurai/phalcon-sqlsrv)[ RSS](/packages/ai-zamurai-phalcon-sqlsrv/feed)WikiDiscussions develop Synced 2w ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

Phalcon - MS SQL Server (PDO) Adapter
=====================================

[](#phalcon---ms-sql-server-pdo-adapter)

Microsoft SQL Server adapter for [Phalcon Framework](https://phalconphp.com/) using PDO (`pdo_sqlsrv`).

Provides a complete SQL Server integration including a PDO adapter, SQL dialect, result set handler, debug listener, and database logger.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Phalcon &gt;= 4.0 (`ext-phalcon`)
- PHP extension: `pdo_sqlsrv`
- Microsoft SQL Server 2012+

Installation
------------

[](#installation)

```
composer require baka/phalcon-sqlsrv
```

Quick Start
-----------

[](#quick-start)

Register the database service in your Phalcon DI container:

```
$di->set('db', function () use ($config) {
    return new \Phalcon\Db\Adapter\Pdo\Sqlsrv([
        'host'     => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname'   => $config->database->name,
    ]);
});
```

Components
----------

[](#components)

### Adapter (`Phalcon\Db\Adapter\Pdo\Sqlsrv`)

[](#adapter-phalcondbadapterpdosqlsrv)

The main database adapter. Extends `Phalcon\Db\Adapter\Pdo\AbstractPdo` and provides:

- SQL Server connection via `pdo_sqlsrv` DSN (with `LoginTimeout=3`, `TrustServerCertificate=true`)
- Column metadata retrieval (`describeColumns`)
- Query execution with scrollable cursor support (auto-switches to forward-only for `exec` statements)
- `PDO::ERRMODE_EXCEPTION` and `PDO::ATTR_STRINGIFY_FETCHES` enabled by default

```
use Phalcon\Db\Adapter\Pdo\Sqlsrv;

$connection = new Sqlsrv([
    'host'     => 'localhost',
    'username' => 'sa',
    'password' => 'YourPassword',
    'dbname'   => 'my_database',
]);

// Query with parameters
$results = $connection->query('SELECT * FROM users WHERE active = ?', [1]);

// Fetch all rows
$rows = $connection->fetchAll('SELECT * FROM users');

// Execute (INSERT/UPDATE/DELETE)
$connection->execute('UPDATE users SET active = 0 WHERE id = ?', [5]);
```

### Dialect (`Phalcon\Db\Dialect\Sqlsrv`)

[](#dialect-phalcondbdialectsqlsrv)

Generates SQL Server-specific SQL. Handles:

- **Pagination**: `OFFSET ... FETCH NEXT` (instead of MySQL's `LIMIT`)
- **Locking**: `WITH (UPDLOCK)` for exclusive locks, `WITH (NOLOCK)` for shared locks
- **DDL**: `CREATE TABLE`, `ALTER TABLE`, `DROP TABLE`, `CREATE VIEW`, `DROP VIEW`
- **Schema introspection**: `describeColumns`, `describeIndexes`, `describeReferences`, `tableExists`, `viewExists`
- **Index / Foreign Key management**: `addIndex`, `dropIndex`, `addForeignKey`, `dropForeignKey`

### Result (`Phalcon\Db\Result\PdoSqlsrv`)

[](#result-phalcondbresultpdosqlsrv)

Wraps PDO statement results. Overrides `numRows()` to use `PDOStatement::rowCount()` for SQL Server compatibility.

### DbListener (`Phalcon\Db\DbListener`)

[](#dblistener-phalcondbdblistener)

Debug listener that logs SQL queries to stdout:

```
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Db\DbListener;

$eventsManager = new EventsManager();
$eventsManager->attach('db', new DbListener());

$connection->setEventsManager($eventsManager);
$connection->debug = true;
```

### Database Logger (`Phalcon\Logger\Adapter\Database`)

[](#database-logger-phalconloggeradapterdatabase)

Stores log entries in a database table with context (process, user, datetime, IP, browser):

```
use Phalcon\Logger\Adapter\Database as DbLogger;
use Phalcon\Logger;

$adapter = new DbLogger('main', [
    'db'       => $connection,
    'table'    => 'logs',
    'username' => 'admin',
]);

$logger = new Logger('main', ['main' => $adapter]);
$logger->info('User logged in');
```

Project Structure
-----------------

[](#project-structure)

```
Phalcon/
├── Db/
│   ├── Adapter/Pdo/Sqlsrv.php   # PDO Adapter
│   ├── Dialect/Sqlsrv.php        # SQL Dialect
│   ├── Result/PdoSqlsrv.php     # Result Set
│   └── DbListener.php           # Debug Listener
└── Logger/
    └── Adapter/Database.php      # Database Logger

```

Documentation &amp; Workflow
----------------------------

[](#documentation--workflow)

Documentation under [`docs/`](docs/) and the Git / review workflow used in this repository are organized following the [feel-flow/ai-spec-driven-development](https://github.com/feel-flow/ai-spec-driven-development) framework — a spec-driven development approach optimized for AI coding agents. Start at [`docs/MASTER.md`](docs/MASTER.md) for the documentation map.

Credits
-------

[](#credits)

Forked from [bakaphp/phalcon-sqlsrv](https://github.com/bakaphp/phalcon-sqlsrv).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance80

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

105d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/134047047?v=4)[AI ZAMURAI](/maintainers/ai-zamurai)[@ai-zamurai](https://github.com/ai-zamurai)

---

Top Contributors

[![fffokazaki](https://avatars.githubusercontent.com/u/205710300?v=4)](https://github.com/fffokazaki "fffokazaki (17 commits)")[![ai-zamurai](https://avatars.githubusercontent.com/u/134047047?v=4)](https://github.com/ai-zamurai "ai-zamurai (13 commits)")[![kaioken](https://avatars.githubusercontent.com/u/118385?v=4)](https://github.com/kaioken "kaioken (7 commits)")[![hakimio](https://avatars.githubusercontent.com/u/768105?v=4)](https://github.com/hakimio "hakimio (2 commits)")[![DavisDS](https://avatars.githubusercontent.com/u/120134967?v=4)](https://github.com/DavisDS "DavisDS (1 commits)")

---

Tags

frameworksqlsrvphalcon

### Embed Badge

![Health badge](/badges/ai-zamurai-phalcon-sqlsrv/health.svg)

```
[![Health](https://phpackages.com/badges/ai-zamurai-phalcon-sqlsrv/health.svg)](https://phpackages.com/packages/ai-zamurai-phalcon-sqlsrv)
```

###  Alternatives

[phalcon/devtools

This tools provide you useful scripts to generate code helping to develop faster and easy applications that use with Phalcon framework.

1.3k2.1M54](/packages/phalcon-devtools)[phalcon/incubator

Adapters, prototypes or functionality that can be potentially incorporated to the C-framework.

7203.0M81](/packages/phalcon-incubator)[phalcon/migrations

Run and Generate DB Migrations with Phalcon Framework

281.0M7](/packages/phalcon-migrations)[phalcon/incubator-mailer

Phalcon Incubator Mailer Adapters

1321.1k8](/packages/phalcon-incubator-mailer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
