Skip to content

Commit 966f857

Browse files
committed
Code refactor, using mDB methods
Add pure method to replace array escaping in ?u data Add insert and update (not finished yet) methods
1 parent 5fe8a14 commit 966f857

File tree

3 files changed

+236
-508
lines changed

3 files changed

+236
-508
lines changed

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
Simple static class for working with MySql databases
1+
Simple static/non-static classes for working with MySql databases
22
* **PHP version:** 7.0+
33
* **Composer:** `composer require power/db`
44
* This code was taken as a basis https://github.com/colshrapnel/safemysql
5+
6+
#### Two ways to use: static and non/static
7+
All methods available in both class types
8+
```php
9+
use \Power\DB;
10+
11+
// Non static
12+
$db = new \Power\mDB('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
13+
// Select all records from users table
14+
$data = $db->getAll('SELECT * FROM ?n', 'users');
15+
16+
// Static
17+
DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
18+
// Select all records from users table
19+
$data = DB::getAll('SELECT * FROM ?n', 'users');
20+
```
21+
522
#### Work with one database
623
```php
724
use \Power\DB;
@@ -22,16 +39,21 @@ DB::getOne('SELECT count(*) FROM `users`');
2239
// Insert some data
2340
$table_name = 'logs';
2441
$data = [
25-
'create_date' => ['now()'], // when the value is an array it will not be escaped, useful for functions or someone else code
42+
'create_date' => DB::pure('now()'), // when you don't need to escape value - use DB::pure method
2643
'login' => 'tester',
2744
'userid' => 5
2845
];
2946
DB::query('INSERT INTO ?n SET ?u', $table_name, $data);
47+
// or user insert method
48+
DB::insert($table_name, $data);
3049
// Get inserted id from last query
3150
echo DB::insertId();
51+
52+
// Update records
53+
DB::update($table_name, $data)
3254
```
3355

34-
#### Work with several databases
56+
#### Work with several databases from static class
3557
```php
3658
use \Power\DB;
3759

0 commit comments

Comments
 (0)