PHPackages                             lianzh/sql - 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. lianzh/sql

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

lianzh/sql
==========

Make the best PHP database operation lib

1.0(6y ago)027Apache License Version 2.0PHPPHP &gt;=5.4

Since Apr 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lianzh/sql)[ Packagist](https://packagist.org/packages/lianzh/sql)[ Docs](https://github.com/lianzh/sql)[ RSS](/packages/lianzh-sql/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

LianzhSQL
=========

[](#lianzhsql)

a light sql query lib for php.

Make the best PHP database operation lib
----------------------------------------

[](#make-the-best-php-database-operation-lib)

- Simple and understandable source code
- Simple configuration, easy to use
- Support multiple databases based on PDO, not coupled, do not rely on third-party libraries
- Moderate function , Easy to integrate
- Support PHP5.4+
- Safe anti-sql injection

Based on the principle of minimum interface
-------------------------------------------

[](#based-on-the-principle-of-minimum-interface)

Developers basically only need to use 2 convenient functions of the Sql class to operate all functions:

```
\LianzhSQL\Sql::ds # get data source object
\LianzhSQL\Sql::assistant # Sql auxiliary class object obtained
```

manual
------

[](#manual)

```
class JptestApp
{

	/**
	 * @var SqlDataSource
	 */
	static $ds = null;

	static function sql_monitor($sql, $dsn_id)
	{
		if (PHP_SAPI === 'cli')
		{
			fwrite(STDOUT, "[sql]: " . print_r($sql,true) . PHP_EOL);
		}
		else
		{
			echo "[sql]: " . print_r($sql,true);
		}
	}

}

function jptest_init()
{
	$dsn = array(
			'type' => 'mysql',

			'dbpath'  => 'mysql:host=127.0.0.1;port=3306;dbname=jptest',
			'login'	=> 'root',
			'password' => '123456',

			'initcmd' => array(
					"SET NAMES 'utf8'",
				),

			'attr'	=> array(
					PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
					PDO::ATTR_PERSISTENT => false,
				),

			'monitor'	=> 'JptestApp::sql_monitor',
		);
	JptestApp::$ds = \LianzhSQL\Sql::ds($dsn);
	var_dump(JptestApp::$ds);

	$result = null;
	// $result = JptestApp::$ds->all('show tables');
	//
	// $result = \LianzhSQL\Sql::assistant( JptestApp::$ds )->select_row('ixr_citys',array('island'=>array(1,'>=')),'id,name,image');
	//
	// $result = \LianzhSQL\Sql::assistant( JptestApp::$ds )->select('ixr_citys',array('id'=>array(1,'>=')),'id,name,image');

	prety_printr( $result );
}
```

Strong search condition generation
----------------------------------

[](#strong-search-condition-generation)

```
use LianzhSQL\SqlHelper;

function assertEqual($var1,$var2){
	if ($var1 !== $var2)
		throw new Exception('Not Equal .');
}

$ds = JptestApp::$ds;
/* @var $ds SqlDataSource */

$cond = "author_id=123 AND bookname='仓一鼠'";
$result = SqlHelper::parse_cond($ds,$cond,FALSE);
assertEqual($result,"author_id=123 AND bookname='仓一鼠'");

// ? Is an array
$cond = array(
	'author_id' => 123,
	'bookname' => '仓一鼠',
);
$result = SqlHelper::parse_cond($ds,$cond,FALSE);
assertEqual($result,"author_id = 123 AND bookname = '仓一鼠'");

// > < !=
$cond = array(
	'author_id' => array(123, '>'),
	'bookname' => '仓一鼠',
);
$result = SqlHelper::parse_cond($ds,$cond,FALSE);
assertEqual($result,"author_id > 123 AND bookname = '仓一鼠'");

$cond = array(
	'author_id' => array(123, '','OR'),array(5,'','AND',true),
);
$result = SqlHelper::parse_cond($ds,$cond,FALSE);
assertEqual($result,"author_id != 123 AND book_price > market_parce");
```

Simple configuration and multi-database support
-----------------------------------------------

[](#simple-configuration-and-multi-database-support)

```
Description of configuration information
1. type = mysql/mariadb
{
		dbpath: mysql:host=${host};port=${port};dbname=${database}
		initcmd: [
			SET NAMES '${charset}',
		]
}

2. type = pgsql
{
		dbpath: pgsql:host=${host};port=${port};dbname=${database}
		initcmd: [
			SET NAMES '${charset}',
		]
}

3. type = sybase
{
		dbpath: sybase:host=${host};port=${port};dbname=${database}
		initcmd: [
			SET NAMES '${charset}',
		]
}

4. type = sqlite
{
		dbpath: sqlite:${file}
		initcmd: [

		]
}

5. type = mssql
{
		Windows:
		dbpath: sqlsrv:server=${host};port=${port};database=${database}

		Linux:
		dbpath: dblib:host=${host};port=${port};dbname=${database}

		initcmd: [
			SET QUOTED_IDENTIFIER ON,
			SET NAMES '${charset}',
		]
}

If you want to use persistent connections, you can configure attr parameters

attr: [
		PDO::ATTR_PERSISTENT => TRUE,
]

The PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC used by the class cannot be changed
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

2209d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/658da31642a9b88a028b8ccf1a6445c8ac1ae66cce0d5eaf4accd0a5856e72ae?d=identicon)[toohamster](/maintainers/toohamster)

---

Top Contributors

[![toohamster](https://avatars.githubusercontent.com/u/16458414?v=4)](https://github.com/toohamster "toohamster (1 commits)")

---

Tags

phpsql

### Embed Badge

![Health badge](/badges/lianzh-sql/health.svg)

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

###  Alternatives

[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[friedolinfoerder/wp-activerecord

An ActiveRecord implementation for WordPress

237.2k](/packages/friedolinfoerder-wp-activerecord)

PHPackages © 2026

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