PHPackages                             amkt922/ssql - 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. [Database &amp; ORM](/categories/database)
4. /
5. amkt922/ssql

ActiveLibrary[Database &amp; ORM](/categories/database)

amkt922/ssql
============

The simple database access library.

0.0.1(12y ago)128[4 issues](https://github.com/amkt922/ssql/issues)PHP

Since Aug 21Pushed 4y ago2 watchersCompare

[ Source](https://github.com/amkt922/ssql)[ Packagist](https://packagist.org/packages/amkt922/ssql)[ RSS](/packages/amkt922-ssql/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (3)Used By (0)

SSql
====

[](#ssql)

[![Build Status](https://camo.githubusercontent.com/e267187d6dda5ea98d8b0f3b3acee632b907e5fe45f507cf2aa9089f9fa5d0eb/68747470733a2f2f7472617669732d63692e6f72672f616d6b743932322f7373716c2e706e67)](https://travis-ci.org/amkt922/ssql)

The SSql is a simple database access library.
It has two main features:

- build a sql with methods and execute it(Simple Query)
- execute a sql written in a sql-file outside an app(Simple Sql).

The second is inspired by the dbflute outside sql.
[dbflute](http://dbflute.seasar.org/)
[About OutsideSql](http://dbflute.seasar.org/ja/manual/function/ormapper/outsidesql/index.html)

SSqlはシンプルなデータベースアクセスライブラリです。 主に2つの機能があります。

- メソッドチェインによるSQLの構築と実行
- sqlファイルに記述されたSQLの実行

2つ目の機能はdbfluteの外出しSQLに感銘を受けて作りました。
[dbflute](http://dbflute.seasar.org/)
[dbfluteの外出しSQL](http://dbflute.seasar.org/ja/manual/function/ormapper/outsidesql/index.html)

Motive
======

[](#motive)

In the actual project, sometimes we need to access databases with more complex sqls than functions a ORM library has.
When executing them with a ORM, sources are going to be more complicated generally.
I need to embed them in the sources, and I don't know whether they are corrent grammertically.
*The dbflute* has solved such matters with a function that is called *outside sql*, however the dbflute is implemented in Java.
I have wanted to such a library in PHP, and then implemented a library that has outside sql feature.

動機
==

[](#動機)

実際の業務では、ORMが持っている機能以上のDBへのアクセス処理を実装する必要が時々あります。
ORMの機能でそのようなSQLを発行する場合、大抵は実際にWebアプリケーションで確認するまで文法的に正しいかはわかりません。
dbfluteはそのような問題を外出しSQLで解決しています。ただdbfluteはJavaで実装されており、PHPでそのようなライブラリが欲しかったため、PHPで外出しSQLを実装したライブラリです。

What is the outside sql?
========================

[](#what-is-the-outside-sql)

The *outside sql* is a function that execute a sql that is written in sql file.
You write a sql with comment that is called *a parameter comment*.

外出しSQLって？
=========

[](#外出しsqlって)

外出しSQLとはテキストファイルに記載されたSQLを実行する機能です。
パラメータコメントと呼ばれるコメントとともにSQLを記載します。

What is the Parameter comment?
==============================

[](#what-is-the-parameter-comment)

Its example is below.
/\*IF \*/, /\*BEGIN\*/ and so on are parameter comments.

```
/*IF paging*/
SELECT
     id
     , name
     , status
     , created_at
-- ELSE SELECT count(id)
/*END*/
FROM
    user
/*BEGIN*/
WHERE
    /*IF name != null*/
    name like /*name*/'%to'
    /*END*/
    /*IF status != null*/
    AND status = /*statu*/1
    /*END*/
/*IF paging*/
ORDER BY id asc
/*END*/
```

パラメータコメントって？
============

[](#パラメータコメントって)

機能はdbfluteを模倣しているので、dbfluteの外付けSQLのページでご確認ください。
[About OutsideSql](http://dbflute.seasar.org/ja/manual/function/ormapper/outsidesql/index.html)

Differences from dbflute as of now.
===================================

[](#differences-from-dbflute-as-of-now)

- dbflute's embedded parameter is written with $, but SSql uses @

現時点でのdbfluteとの相違点
=================

[](#現時点でのdbfluteとの相違点)

- dbfluteの埋め込み変数は$を使いますが、SSqlでは@を使います

How to install the SSql.
========================

[](#how-to-install-the-ssql)

```
require_once SSql.php;
use SSql\SSql;
```

just import SSql.php

SSqlのインストール方法
=============

[](#ssqlのインストール方法)

```
require_once SSql.php;
use SSql\SSql;
```

SSql.phpを読み込むだけです。

Requirements, 環境
================

[](#requirements-環境)

- php &gt;= 5.3

Limitation, 制限
==============

[](#limitation-制限)

Supports Sqlite, Mysql and Postgresql, other databases are not support as of now.

MysqlとSqlite, Postgresqlのみサポートしています。他のデータベースは現時点ではサポートしていません。

Usage
=====

[](#usage)

Note: These example are parts of SSql features.
There are many another functions in the SSql, please check test code.
Of course I will set up documents in the future.

Setup
-----

[](#setup)

First of all, set up $config like this,

```
$config = array('database' => array('driver' => 'Sqlite'  'sqlite:./db/db.sqlite3'
									, 'user' => ''
									, 'password' => '')
				'sqlDir' => './sql');
```

Simple Query
------------

[](#simple-query)

When you want to execute a simple sql, you can use SQueryManager(Simple Query).
\* When you don't need to execute complex sql.

```
	$ssql = SSql::connect($config);
	$users = $ssql->createSQry()
					->select(array('id', 'name'))
					->from('User')
					->where(array('name like' => 'sato'))
					->execute();
```

1. connect with the config and get a SSql object
2. let it know you use SQueryManager with *createSQry* method
3. build a sql with some methods, they're *Doctrine* like
4. execute it, and get a Result

Update, Delete, Insert operations are almost same as above.

```
	$ssql = SSql::connect($this->config);
	$users = $ssql->createSQry()
					->delete()
					->from('User')
					->where(array('name like' => 'sato'))
					->execute();
	$ssql->createSQry()
					->update('User')
					->set(array('name' => 'kato'))
					->where(array('id =' => 1))
					->execute();
	$ssql->createSQry()
					->insert()
					->into('User', array('id', 'name'))
					->values(array(array(6, 'tanaka')))
					->execute();
```

They build sqls like below.

```
DELETE FROM User WHERE name like ?;
UPDATE User SET name = ? WHERE id = ?;
INSERT INTO User (id, name) VALUES (?, ?);
```

Simple Sql
----------

[](#simple-sql)

When you want to execute a complicate sql, you can use SSqlManager(Simple Sql).

```
	$ssql = SSql::connect($this->config);
	$users = $ssql->createSSql()
						->selectList('selectUser', array('id' => 1
														, 'status' => 2
														, 'paging' => true));
```

1. create sql files wherever you want. it's path should be set in $config\['sqlDir'\].
2. connect with the config and get SSql object(same as Simple Query)
3. execute selectList with sqlfile name(without extension) and parameters for sqlfile

```
/*IF paging*/
SELECT
     id
     , name
     , status
     , created_at
-- ELSE SELECT count(id)
/*END*/
FROM
    user
/*BEGIN*/
WHERE
    /*IF id != null*/
    id = /*id*/2
    /*END*/
	/*IF status != null*/
	AND status = /*status*/10
	/*END*/
/*IF paging*/
ORDER BY id asc
/*END*/

```

SSql builts a sql below and execute.
The written parameters in the selectUser.sql, 2 of id and 10 of status, are trimmed. This advantage of sql file with parameter comment is that you can build and test sql in Database tool(e.g MySqlWorkbench), and then controll parameters in you application with parameter.

```
SELECT
     id
     , name
     , status
     , created_at
FROM
    user
WHERE
    id = 1
	AND status = 2
ORDER BY id asc

```

If you don't pass id, AND is removed automatically.

```
SELECT
     id
     , name
     , status
     , created_at
FROM
    user
WHERE
	status = 2
ORDER BY id asc

```

If parameter, *paging* is false, ELSE line is valid and ORDER is removed.

```
SELECT count(id)
FROM
    user
WHERE
    id = 1
	AND status = 2
```

Others
------

[](#others)

The SSql has beginTransaction, commit, rollback methods itself.

```
	$ssql = SSql::connect($this->config);
	$ssql->beginTransaction();

	~~~~~~update data~~~~~~~~

	if ($success) {
		$ssql->commit();
	} else {
		$ssql->rollback();
	}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.8% of commits — single point of failure

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

Unknown

Total

1

Last Release

4649d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/231ebadac740c836f616b10efcc0f21ebace177f367a49d308d84afb7da0baf4?d=identicon)[amkt922](/maintainers/amkt922)

---

Top Contributors

[![amkt922](https://avatars.githubusercontent.com/u/3191521?v=4)](https://github.com/amkt922 "amkt922 (81 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

### Embed Badge

![Health badge](/badges/amkt922-ssql/health.svg)

```
[![Health](https://phpackages.com/badges/amkt922-ssql/health.svg)](https://phpackages.com/packages/amkt922-ssql)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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