entraigas/slimdb 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

entraigas/slimdb

Composer 安装命令:

composer require entraigas/slimdb

包简介

Slim Database, a wrapper around pdo

README 文档

README

Small db layer around the PDO and PDO statement.

The package goal used to be small and handy, with the basic, commonly used db functions (like select, update, insert and delete). Now it's more ambitious, and it's no so small and basic. Note: there's only support for mysql and sqlite.

Installing the package

You can download the package directly from GitHub Or install it using composer.json file

{
	"require": {
		"entraigas/slimdb": "v1.2.1"
	}
}

Db Setup

The configuration it's done using arrays. In this example, there are two db settings:

  • the first has 'portal' as connection name, and it's a mysql db.
  • the second has 'admin' as connection name, and it's a sqlite db.

Finally, there is a 'default' connection name configured with the 'portal' value.

//database configuration array
$portal => array(
	'driver' => 'mysql',
	'getPdo' => function(){
			//validate PDO extensions
			if (!defined('\PDO::ATTR_DRIVER_NAME')) return false; //PDO is not available
			if (!extension_loaded('pdo_mysql')) return false; //pdo_mysql extension not loaded
			//make connection
			$pdo = new \PDO("mysql:host=127.0.0.1;port=3306;dbname=testdb", 'user', 'password');
			//default connection settings
			$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
			$pdo->query("SET NAMES 'utf8'");
			//done, return pdo object
			return $pdo;
		}
);
$admin => array(
	'driver' => 'sqlite',
	'getPdo' => function(){
			//validate PDO extensions
			if (!defined('\PDO::ATTR_DRIVER_NAME')) return false; //PDO is not available
			if (!extension_loaded('pdo_sqlite')) return false; //pdo_sqlite extension not loaded
			//make connection
			$pdo = new \PDO("sqlite:/path/to/database.db");
			//default connection settings
			$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
			//done, return pdo object
			return $pdo;
		}
);


//initialize SlimDb
\SlimDb\SlimDb::configure('portal', $portal);
\SlimDb\SlimDb::configure('admin', $admin);

//set the default connection
\SlimDb\SlimDb::setDefaultConnection('portal');

There are many classes bundled with the package. Depending on what you are trying to do, you should use one over the other. Here is a list:

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固