承接 tueena-lib/sql 相关项目开发

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

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

tueena-lib/sql

Composer 安装命令:

composer require tueena-lib/sql

包简介

A (very restricted) wrapper around PDO to make database access mockable in unit tests.

README 文档

README

A (very restricted) wrapper around PDO to make database access mockable in unit tests.

Features

  • Methods for SELECT, INSERT, UPDATE and DELETE queries.
  • Prepared statements, transactions.
  • Allows to pass parameters as associative array.
  • Right now only works with MySQL.

Usage

<?php

namespace tueenaLib\sql;

// Initialisation
$driver = new MySqlDriver('localhost', 'root', 'myPasswd', 'myDatabase', 3306);
$sql = new Sql($driver);

// Usage

// INSERT with prepared statement (works also with UPDATEs, SELECTs and DELETEs).
$preparedStatement = new PreparedStatement('INSERT into testtable (foo, bar) VALUES (:foo, :bar)');
$sql->insertWithPreparedStatement($preparedStatement, ['foo' => 'value1', 'bar' => 'value2']);

$result = $sql->insertWithPreparedStatement($preparedStatement, ['foo' => 'value2', 'bar' => 'value3']);
$affectedRows = $result->getNumAffectedRows();
$lastInsertId = $result->getLastInsertId(); // Works only for INSERT queries, of course.

// Transactions
$transaction = $sql->beginTransaction();
// UPDATE without prepared statement (like SELECTs, INSERTs and DELETEs)
$sql->update(
	'UPDATE testtable SET foo = :foo WHERE id = :id',
	[
		'foo' => 'value4',
		'id' => 1
	],
	$transaction // pass in the transaction object.
);
$sql->rollBack($transaction); // or use Sql::commit($transaction)

$result = $sql->select('SELECT * FROM testtable');
$numRows = $result->getNumRows();
$row1 = $result->fetchAssoc(); // associative array
$row2 = $result->fetchNumeric(); // numeric array
$row3 = $result->fetchNumeric(); // returns null if there is no more row.

License

MIT

Requirements

  • php >= 7.0.0
  • pdo

Installation

If you use Composer:

composer require tueena-lib/sql

Otherwise just download the files and use it.

Contact

Bastian Fenske bastian.fenske@tueena.org

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固