2017 © Pedro Peláez
 

library php-db

php pdo library

image

tonychen/php-db

php pdo library

  • Monday, June 18, 2018
  • by TonyChen-SH
  • Repository
  • 0 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

数据库类库

基于slim-pdo做的一个pdo数据库类, (*1)

StyleCI Build Status, (*2)

Install

  // 把下面的代码片段,加入到composer.json文件里面
  // 由于tony这个命名空间在packagist已经有人用了,我的加不进去,暂代用直连方式
  "require": {
    "tony/php-db": "0.1"
  },
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/TonyChen-SH/php-db.git"
    }
  ]

Usage

require_once 'vendor/autoload.php';

$pdo = \Tony\DB\DbFactory::getInstance(['dsn' => 'mysql:host=192.168.1.11;dbname=test;charset=utf8','user'=>'root', 'password' => '123456']);

// 使用原生
$res = $pdo->fetchRow('SELECT * FROM player');

//------------------------使用sql builder---------------------------//

// SELECT * FROM users WHERE id = ?
$selectStatement = $pdo->select()
                       ->from('users')
                       ->where('id', '=', 1234);

$stmt = $selectStatement->execute();
$data = $stmt->fetch();

// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
$insertStatement = $pdo->insert(array('id', 'usr', 'pwd'))
                       ->into('users')
                       ->values(array(1234, 'your_username', 'your_password'));

$insertId = $insertStatement->execute(false);

// UPDATE users SET pwd = ? WHERE id = ?
$updateStatement = $pdo->update(array('pwd' => 'your_new_password'))
                       ->table('users')
                       ->where('id', '=', 1234);

$affectedRows = $updateStatement->execute();

// DELETE FROM users WHERE id = ?
$deleteStatement = $pdo->delete()
                       ->from('users')
                       ->where('id', '=', 1234);

$affectedRows = $deleteStatement->execute();

slim-pdo documentation

The Versions

18/06 2018

dev-develop

dev-develop

php pdo library

  Sources   Download

The Requires

 

The Development Requires

by Tony Chen

11/05 2018

v0.1.2

0.1.2.0

php mysql

  Sources   Download

The Requires

 

The Development Requires

by Tony Chen

15/12 2017

v0.1.1

0.1.1.0

php mysql

  Sources   Download

The Requires

 

The Development Requires

by Tony Chen

07/06 2017

dev-master

9999999-dev

php mysql

  Sources   Download

The Requires

 

The Development Requires

by Tony Chen

07/06 2017

v0.1

0.1.0.0

php mysql

  Sources   Download

The Requires

 

The Development Requires

by Tony Chen