https://github.com/shuchkin/react-mysqli
Asynchronous & non-blocking MySQL driver for ReactPHP (MySQLi Pool)
https://github.com/shuchkin/react-mysqli
Last synced: about 23 hours ago
JSON representation
Asynchronous & non-blocking MySQL driver for ReactPHP (MySQLi Pool)
- Host: GitHub
- URL: https://github.com/shuchkin/react-mysqli
- Owner: shuchkin
- License: mit
- Created: 2020-03-09T14:11:26.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-06T22:07:51.000Z (over 4 years ago)
- Last Synced: 2025-04-09T13:07:28.655Z (14 days ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# React MySQLi 0.1
Asynchronous & non-blocking MySQLi driver for [ReactPHP](https://github.com/reactphp/react).
Require [php-mysqlnd](http://php.net/manual/ru/book.mysqlnd.php) extension
## Install
```bash
composer require shuchkin/react-mysqli
```## CONNECTION and SELECT
```php
$loop = \React\EventLoop\Factory::create();$db = \Shuchkin\ReactMySQLi\Client::connect($loop, 'localhost', 'root', '', 'my_db' );
$db->query('SELECT id,name,email FROM user')->then(
function (\Shuchkin\ReactMySQLi\Result $result) {
print_r( $result->all() );
},
function ( \Exception $ex ) {
trigger_error( $ex->getMessage() );
}
);
$loop->run();
```
```
Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Gianni Rodari
[email] => [email protected]
)[1] => stdClass Object
(
[id] => 2
[name] => Rikki-Tikki-Tavi
[email] => [email protected]
))
```
## INSERT
```php
$db->query("INSERT INTO user SET name='Sergey',email='[email protected]'")->then(
function (\Shuchkin\ReactMySQLi\Result $result) {
print_r($result->insert_id); // 12345
},
function ( \Exception $ex ) {
trigger_error( $ex->getMessage() );
}
);
```
### UPDATE
```php
$db->query("UPDATE user SET email='[email protected]' WHERE id=12345")->then(
function (\Shuchkin\ReactMySQLi\Result $result) {
print_r($result->affected_rows);
},
function ( \Exception $ex ) {
trigger_error( $ex->getMessage() );
}
);
```
### DELETE
```php
$db->query('DELETE FROM user WHERE id=12345')->then(
function (\Shuchkin\ReactMySQLi\Result $result) {
print_r($result->affected_rows);
},
function ( \Exception $ex ) {
trigger_error( $ex->getMessage() );
}
);
```