33Non-blocking MySQLi database access with PHP.
44Designed to work with [ reactphp/react] ( https://github.com/reactphp/react ) .
55
6+ [ ![ Build Status] ( https://travis-ci.org/dustingraham/react-mysql.svg?branch=master )] ( https://travis-ci.org/dustingraham/react-mysql )
7+
8+ ## Quickstart
9+
10+ $db = new \DustinGraham\ReactMysql\Database(
11+ ['localhost', 'apache', 'apache', 'react_mysql_test']
12+ );
13+
14+ $db->statement('SELECT * FROM simple_table WHERE id = :test', [':test' => 2])
15+ ->then(function(\mysqli_result $result)
16+ {
17+ $rows = $result->fetch_all(MYSQLI_ASSOC);
18+ });
19+
20+ $db->shuttingDown = true;
21+ $db->loop->run();
22+
23+ Setting ` shuttingDown ` to true will allow the loop to exit once the query has resolved.
624
725## Working
826
9- This __ is__ working. But it is nowhere near complete.
27+ This __ is__ working. But it is nowhere near complete. Check out the example file
28+ as well as the unit tests for more examples.
1029
11- $ ./run
12- Starting loop...
13- DB Created.
30+ $ ./example
31+ Creating database....done!
1432 Run Query: 0
1533 Found rows: 0
1634 Run Query: 1
1735 Found rows: 1
18- Current memory usage: 735.117K
36+ Current memory usage: 868.164K
1937 Run Query: 2
20- Found rows: 0
38+ Found rows: 1
2139 Run Query: 3
2240 Found rows: 1
2341 Run Query: 4
24- Found rows: 1
25- Current memory usage: 735.117K
42+ Found rows: 0
43+ Current memory usage: 868.164K
2644 Run Query: 5
2745 Found rows: 0
28- Current memory usage: 733.602K
29- Current memory usage: 733.602K
30- Current memory usage: 733.602K
46+ Current memory usage: 865.719K
47+ Current memory usage: 865.719K
48+ Current memory usage: 865.719K
3149 Loop finished, all timers halted.
3250
3351This won't work out of the box without the database configured.
34- As of this point, database configuration is hard coded.
35- Still need to pull out the configs. You will also need to
36- set up a database with some data to query. Check back later
37- for more!
52+ You will also need to set up a database with some data to query.
3853
39- ## TODO
54+ ## Unit Tests
4055
41- A lot.
56+ The example and unit tests expect a database called ` react_mysql_test ` which it
57+ will populate with the proper tables each time it runs. It also expects ` localhost `
58+ and a user ` apache ` with password ` apache ` .
59+
60+ ## TODO
4261
4362This is not production ready. Still tons to do on the query builder.
4463While I hate to reinvent the wheel, I have not found a lightweight
@@ -52,23 +71,20 @@ These are just plans for now. It may change wildly as we develop.
5271
5372Here is an example of what is currently working for the most part.
5473
55- $loop = React\EventLoop\Factory::create();
56-
57- ConnectionFactory::init($loop, ['db_host', 'db_user', 'db_pass', 'db_name']);
58-
59- $db = new \DustinGraham\ReactMysql\Database();
74+ $db = new \DustinGraham\ReactMysql\Database(
75+ ['localhost', 'apache', 'apache', 'react_mysql_test']
76+ );
6077
61- $db->createCommand("SELECT * FROM `table` WHERE id = :id;", [':id' => $id])
62- ->execute()->then(
63- function($result)
78+ $db->statement('SELECT * FROM simple_table WHERE id = :test', [':test' => 2])
79+ ->then(function(\mysqli_result $result)
6480 {
6581 $rows = $result->fetch_all(MYSQLI_ASSOC);
66- $result->close();
6782
6883 // Do something with $rows.
69- }
70- );
84+ });
7185
86+ $db->shuttingDown = true;
87+ $db->loop->run();
7288
7389### Original Big Picture Plans
7490
0 commit comments