Skip to content

Commit

Permalink
Code refactor, using mDB methods
Browse files Browse the repository at this point in the history
Add pure method to replace array escaping in ?u data
Add insert and update (not finished yet) methods
  • Loading branch information
alexdnepro committed Nov 10, 2021
1 parent 5fe8a14 commit 966f857
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 508 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
Simple static class for working with MySql databases
Simple static/non-static classes for working with MySql databases
* **PHP version:** 7.0+
* **Composer:** `composer require power/db`
* This code was taken as a basis https://github.com/colshrapnel/safemysql

#### Two ways to use: static and non/static
All methods available in both class types
```php
use \Power\DB;

// Non static
$db = new \Power\mDB('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Select all records from users table
$data = $db->getAll('SELECT * FROM ?n', 'users');

// Static
DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Select all records from users table
$data = DB::getAll('SELECT * FROM ?n', 'users');
```

#### Work with one database
```php
use \Power\DB;
Expand All @@ -22,16 +39,21 @@ DB::getOne('SELECT count(*) FROM `users`');
// Insert some data
$table_name = 'logs';
$data = [
'create_date' => ['now()'], // when the value is an array it will not be escaped, useful for functions or someone else code
'create_date' => DB::pure('now()'), // when you don't need to escape value - use DB::pure method
'login' => 'tester',
'userid' => 5
];
DB::query('INSERT INTO ?n SET ?u', $table_name, $data);
// or user insert method
DB::insert($table_name, $data);
// Get inserted id from last query
echo DB::insertId();

// Update records
DB::update($table_name, $data)
```

#### Work with several databases
#### Work with several databases from static class
```php
use \Power\DB;

Expand Down
Loading

0 comments on commit 966f857

Please sign in to comment.