承接 sinevia/php-library-sqldb 相关项目开发

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

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

sinevia/php-library-sqldb

Composer 安装命令:

composer require sinevia/php-library-sqldb

包简介

PHP Library for Working with SQL databases

README 文档

README

Gitpod Ready-to-Code

PHP Library SqlDB

PHP Library for working with SQL databases.

No Dependencies Build status GitHub stars HitCount

Features

  • MySQL, SQlite and SQLiteDB (SQLite in the cloud) supported
  • Unified data types. The data types are developer orientated (string, text, integer, float, blob). These are then translated to the correct column type for the corresponding database.
  • Fluent interface for building queries

Installation

  1. Via composer command line
composer require sinevia/php-library-sqldb
  1. Via composer file:

Add the latest stable version to your composer file, and update via composer

"require": {
    "sinevia/php-library-sqldb": "3.8.0"
}

Data Types

Data Type MySQL Data Type SQLite Data Type
STRING VARCHAR (255) TEXT
TEXT LONG TEXT TEXT
INTEGER BIG INT INTEGER
FLOAT DOUBLE REAL
BLOB LONG BLOB TEXT

Usage

1) Creating a new database instance

// MySQL
$db = new Sinevia\SqlDB(array(
    'database_type'=>'mysql',
    'database_name'=>'db_name',
    'database_host'=>'db_host',
    'database_user'=>'db_user',
    'database_pass'=>'db_pass'
));

// SQLite (creating a new SQLite database, if it does not exist)
$db = new Sinevia\SqlDB(array(
    'database_type'=>'sqlite',
    'database_name'=>'db_name',
    'database_host'=>'db_host',
    'database_user'=>'db_user',
    'database_pass'=>'db_pass'
));

// SQLiteDB (SQLite in the cloud)
$db = new Sinevia\SqlDB(array(
    'database_type'=>'sqlitedb',
    'database_host'=>'sqlitedb_api_url',
    'database_pass'=>'sqlitedb_api_key'
));

// Using existing PDO instance
$db = new Sinevia\SqlDB($pdo);

2) Drop a database

Depending on your database hosting this may or may not be supported

// Dropping a database
$db->drop();

3) Creating a new table

// Check if table already exists?
if ($db->table("person")->exists() == false) {
    // Create table
    $db->table("person")
        ->column("Id", "INTEGER", "NOT NULL PRIMARY KEY AUTO_INCREMENT")
        ->column("FirstName", "STRING")
        ->column("LastName", "STRING")
        ->create();
}

3) Drop a table

// Dropping a table
$isOk = $db->table("person")->drop();

3) Inserting rows

$isOk = $db->table('person')->insert([
    'FirstName' => 'Peter',
    'LastName' => 'Pan',
]);

// Getting the new autoincremented ID
$personId = $db->lastInsertId();

4) Selecting rows

//Selects all the rows from the table
$rows = $db->table("person")->select();

// Selects the rows where the column NAME is different from Peter, in descending order
$rows = $db->table("person")
    ->where("Name", "!=", "Peter")
    ->orderby("Name","desc")
    ->select();

5) Updating rows

// Delete row by ID
$isOk = $db->table("person")
    ->where("Id", "==", "1")
    ->update([
        'LastName' => 'Voldemort'
    ]);

5) Deleting rows

// Delete row by ID
$isOk = $db->table("person")
    ->where("Id", "==", "1")
    ->delete();

// Delete all rows in the table
$isOk = $db->table("person")->delete();

Helper Functions

1) Generating UUIDs

$uuid = Sinevia\SqlDB::uuid();

2) Generating HUIDs

HUIDs are human friendly unique identifiers, which are date based.

$uid20 = Sinevia\SqlDB::uid(); // 20 digits default
$uid32 = Sinevia\SqlDB::uid(32); // 32 digits

Related Projects

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2018-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固