An open API service indexing awesome lists of open source software.

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)

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() );
}
);
```