All Projects → swlib → Swpdo

swlib / Swpdo

Licence: apache-2.0
Swoole Coroutine SQL component like PDO | 0成本迁移PDO到Swoole高性能协程客户端

Projects that are alternatives of or similar to Swpdo

Ycsocket
基于swoole的socket框架,支持协程版MySQL、Redis连接池,已用于大型RPG游戏服务端
Stars: ✭ 77 (+20.31%)
Mutual labels:  coroutine, mysql, swoole
Imi
imi 是基于 Swoole 的 PHP 协程开发框架,它支持 Http、Http2、WebSocket、TCP、UDP、MQTT 等主流协议的服务开发,特别适合互联网微服务、即时通讯聊天im、物联网等场景!。QQ群:17916227
Stars: ✭ 680 (+962.5%)
Mutual labels:  coroutine, mysql, swoole
Easydb
Easy-to-use PDO wrapper for PHP projects.
Stars: ✭ 624 (+875%)
Mutual labels:  pdo, mysql
Leafpub
Simple, beautiful, open source publishing.
Stars: ✭ 645 (+907.81%)
Mutual labels:  pdo, mysql
Paysdk
PHP 集成支付 SDK ,集成了支付宝、微信支付的支付接口和其它相关接口的操作。支持 php-fpm 和 Swoole,所有框架通用。宇润PHP全家桶技术支持群:17916227
Stars: ✭ 723 (+1029.69%)
Mutual labels:  coroutine, swoole
Easyswoole
swoole,easyswoole,swoole framework
Stars: ✭ 4,409 (+6789.06%)
Mutual labels:  coroutine, swoole
Groupco
PHP的服务化框架。适用于Api、Http Server、Rpc Server;帮助原生PHP项目转向微服务化。出色的性能与支持高并发的协程相结合
Stars: ✭ 473 (+639.06%)
Mutual labels:  mysql, swoole
Php frameworks analysis
php框架源码分析
Stars: ✭ 57 (-10.94%)
Mutual labels:  pdo, mysql
Yurunoauthlogin
PHP 第三方登录授权 SDK,集成了QQ、微信、微博、Github等常用接口。支持 php-fpm 和 Swoole,所有框架通用。QQ群:17916227
Stars: ✭ 330 (+415.63%)
Mutual labels:  coroutine, swoole
Swoft Db
[READ ONLY] Database Compoment for Swoft
Stars: ✭ 25 (-60.94%)
Mutual labels:  coroutine, swoole
Ezsql
PHP class to make interacting with a database ridiculusly easy
Stars: ✭ 804 (+1156.25%)
Mutual labels:  pdo, mysql
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (+1253.13%)
Mutual labels:  coroutine, swoole
Dibi
Dibi - smart database abstraction layer
Stars: ✭ 373 (+482.81%)
Mutual labels:  pdo, mysql
Hyperf
🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
Stars: ✭ 4,206 (+6471.88%)
Mutual labels:  coroutine, swoole
Swoft
🚀 PHP Microservice Full Coroutine Framework
Stars: ✭ 5,420 (+8368.75%)
Mutual labels:  coroutine, swoole
Php Mysql Class
Simple MySQL class written in PHP, for interfacing with a MySQL database.
Stars: ✭ 349 (+445.31%)
Mutual labels:  pdo, mysql
Mysqldump Php
PHP version of mysqldump cli that comes with MySQL
Stars: ✭ 975 (+1423.44%)
Mutual labels:  pdo, mysql
Simps
🚀 A simple, lightweight and high-performance PHP coroutine framework.
Stars: ✭ 318 (+396.88%)
Mutual labels:  coroutine, swoole
Shadowfax
Run Laravel on Swoole.
Stars: ✭ 325 (+407.81%)
Mutual labels:  coroutine, swoole
Fluentpdo
A PHP SQL query builder using PDO
Stars: ✭ 783 (+1123.44%)
Mutual labels:  pdo, mysql

SwPDO

Latest Version Build Status Php Version Swoole Version SwPDO License

Introduction

Traditional PDO to Swoole Coroutine migration plan without cost.

中文文档

Install

The best way to install: Composer :

composer require swlib/swpdo

Coroutine

The bottom layer of Swoole implements coroutine scheduling, and the business layer does not need to be aware. Developers can use synchronization code writing methods to achieve the effect and ultra-high performance of asynchronous IO without perception, avoiding the discrete code logic and trapping caused by traditional asynchronous callbacks. Too many callback layers causes the code too difficult to maintain.

It needs to be used in event callback functions such as onRequet, onReceive, and onConnect, or wrapped using the go keyword (swoole.use_shortname is on by default).


Example

Because PDO uses multiple engines, it is difficult at the PHP level to return different instances with class - implemented constructors.

Except that the constructor is different, all methods use in the same way.

query

$options = [
    'mysql:host=127.0.0.1;dbname=test;charset=UTF8',
    'root',
    'root'
];
$sql = 'select * from `user` LIMIT 1';

//PDO
$pdo = new \PDO(...$options);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //strong type
$pdo_both = $pdo->query($sql)->fetch();
$pdo_assoc = $pdo->query($sql)->fetch(\PDO::FETCH_ASSOC);
$pdo_object = $pdo->query($sql)->fetch(\PDO::FETCH_OBJ);
$pdo_number = $pdo->query($sql)->fetch(\PDO::FETCH_NUM);

//SwPDO
$swpdo = SwPDO::construct(...$options); //default is strong type
$swpdo_both = $swpdo->query($sql)->fetch();
$swpdo_assoc = $swpdo->query($sql)->fetch(\PDO::FETCH_ASSOC);
$swpdo_object = $swpdo->query($sql)->fetch(\PDO::FETCH_OBJ);
$swpdo_number = $swpdo->query($sql)->fetch(\PDO::FETCH_NUM);

var_dump($pdo_both === $swpdo_both);
var_dump($pdo_assoc === $swpdo_assoc);
var_dump($pdo_object == $swpdo_object);
var_dump($pdo_number === $swpdo_number);
//output: true true true true

prepare

//PDO
$pdo = new \PDO(...$options);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //strong type
$statement = $pdo->prepare($sql);
$statement->execute();
$pdo_fetch = $statement->fetch(\PDO::FETCH_ASSOC);
$statement->execute();
$pdo_fetch_all = $statement->fetchAll();
$statement->execute();
$pdo_fetch_all_column = $statement->fetchAll(\PDO::FETCH_COLUMN, 1);
$statement->execute();
$pdo_fetch_column = $statement->fetchColumn();
$statement->execute();

//SwPDO
$swpdo = SwPDO::construct(...$options);
$statement = $swpdo->prepare($sql);
$statement->execute();
$swpdo_fetch = $statement->fetch(\PDO::FETCH_ASSOC);
$statement->execute();
$swpdo_fetch_all = $statement->fetchAll();
$statement->execute();
$swpdo_fetch_all_column = $statement->fetchAll(\PDO::FETCH_COLUMN, 1);
$statement->execute();
$swpdo_fetch_column = $statement->fetchColumn();
$statement->execute();

var_dump($pdo_fetch === $swpdo_fetch); //true
var_dump($pdo_fetch_all === $swpdo_fetch_all); //true
var_dump($pdo_fetch_all_column === $swpdo_fetch_all_column); //true
var_dump($pdo_fetch_column === $swpdo_fetch_column); //true

bind

//PDO
$pdo = new \PDO(...$options);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //strong type
$statement = $pdo->prepare($sql);
$statement->execute(['id' => 1]);
$pdo_bind_exec = $statement->fetch(\PDO::FETCH_ASSOC);

$statement->bindValue(':id', 1);
$statement->execute();
$pdo_bind_val = $statement->fetch(\PDO::FETCH_ASSOC);

$statement->bindParam(':id', $id);
$statement->execute();
$pdo_bind_param = $statement->fetch(\PDO::FETCH_ASSOC);

//SwPDO
$swpdo = SwPDO::construct(...$options);
$statement = $swpdo->prepare($sql);
$statement->execute(['id' => 1]);
$swpdo_bind_exec = $statement->fetch(\PDO::FETCH_ASSOC);

$statement->bindValue(':id', 1);
$statement->execute();
$swpdo_bind_val = $statement->fetch(\PDO::FETCH_ASSOC);

$statement->bindParam(':id', $id);
$statement->execute();
$swpdo_bind_param = $statement->fetch(\PDO::FETCH_ASSOC);

var_dump($pdo_bind_exec === $swpdo_bind_exec); //true
var_dump($pdo_bind_val === $swpdo_bind_val); //true
var_dump($pdo_bind_param === $swpdo_bind_param); //true
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].