承接 gelembjuk/db 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

gelembjuk/db

最新稳定版本:2.0.2

Composer 安装命令:

composer require gelembjuk/db

包简介

PHP Package for DB access from PHP. It contains simple common interface and can be used with many DB engines. It is very simple alternative of PDO

README 文档

README

PHP Package for DB access from PHP. It contains simple common interface and can be used with many DB engines. It is very simple alternative of PDO.

Use it to have simple and fast way to access a DB with an abstract layer. So you can change a DB engine later.

Currently only 2 engines are supported: mysql and mysqli (Gelembjuk\DB\MySQL and Gelembjuk\DB\MySQLi)

Installation

Using composer: gelembjuk/db require: {"gelembjuk/db": "*"}

Usage

require ('vendor/autoload.php');

// simple example to show how to work with 2 DB parelelly in a PHP script

$dbsettings1 = array(
	'user' => 'dbuser',
	'password' => 'dbuserpassword',
	'database' => 'mydb',
	'host' => 'localhost',
	'connectioncharset' => 'utf8',
	'namescharset' => 'utf8'
	);

// different DB
$dbsettings2 = array(
	'user' => 'dbuser',
	'password' => 'dbuserpassword',
	'database' => 'mydb2',
	'host' => 'localhost',
	'connectioncharset' => 'utf8',
	'namescharset' => 'utf8'
	);

$dbengine1 = new Gelembjuk\DB\MySQL($dbsettings1);
$dbengine2 = new Gelembjuk\DB\MySQLi($dbsettings2);
// connection will be established on a first request to a DB

class MyTable extends Gelembjuk\DB\Base {
	public function getUsers() {
		return $this->getRows('SELECT * FROM users');
	}
	public function addUser($name,$email) {
		$sql = "INSERT INTO users (name,email) VALUES ".
			"('".$this->quote($name)."','".$this->quote($email)."')";
		$this->executeQuery();
		
		return getLastInsertedId();
	}
}

$mytable = new MyTable($dbengine1);

$userid1 = $mytable->addUser('User 1','email@gmail.com');
$userid2 = $mytable->addUser('User 2','email2@gmail.com');

print_r($mytable->getUsers());

// this will do same but with different DB
$mytable2 = new MyTable($dbengine2);

print_r($mytable2->getUsers());

Author

Roman Gelembjuk (@gelembjuk)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-07