https://github.com/oliverfindl/database-pdo
Simple PHP database class based on PDO class. This class adds 2 new methods - for ping and bulk insert, which are useful for web scrapers. All PDO functionality is preserved.
https://github.com/oliverfindl/database-pdo
class database pdo php php7 wrapper
Last synced: 27 days ago
JSON representation
Simple PHP database class based on PDO class. This class adds 2 new methods - for ping and bulk insert, which are useful for web scrapers. All PDO functionality is preserved.
- Host: GitHub
- URL: https://github.com/oliverfindl/database-pdo
- Owner: oliverfindl
- License: mit
- Created: 2018-02-10T21:42:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-19T16:44:18.000Z (almost 7 years ago)
- Last Synced: 2025-02-07T08:49:03.572Z (3 months ago)
- Topics: class, database, pdo, php, php7, wrapper
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# database-pdo

[](https://paypal.me/oliverfindl)Simple [PHP](https://secure.php.net/) database class based on [PDO](https://secure.php.net/manual/en/book.pdo.php) class. This class adds 2 new methods - for ping and bulk insert, which are useful for web scrapers. All [PDO](https://secure.php.net/manual/en/book.pdo.php) functionality is preserved.
---
## Install
```bash
$ git clone https://github.com/oliverfindl/database-pdo.git
```## Usage
* Class initialization is same as for [PDO](https://secure.php.net/manual/en/class.pdo.php) class
* Ping method doesn't require any argument
* Insert method has 3 arguments:
* Table (required), into which will be data inserted
* Array (required), which has to be array of associative arrays of data
* Mode (optional):
* \OliverFindl\Database::INSERT_DEFAULT:
```sql
INSERT INTO table (...) VALUES (...), (...), ... ;
```
* \OliverFindl\Database::INSERT_IGNORE:
```sql
INSERT IGNORE INTO table (...) VALUES (...), (...), ... ;
```
* \OliverFindl\Database::INSERT_UPDATE:
```sql
INSERT INTO table (...) VALUES (...), (...), ... ON DUPLICATE KEY UPDATE column = VALUES(column), ... ;
```
* \OliverFindl\Database::INSERT_REPLACE:
```sql
REPLACE INTO table (...) VALUES (...), (...), ... ;
```## Example
```php
require_once("./vendor/database-pdo/src/database.class.php");
// use \OliverFindl\Database; // optional, if you want omit namespace in codetry {
$db = new \OliverFindl\Database(/* ... */); // same arguments as PDO
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
$db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
} catch(\Exception $e) {
exit($e->getMessage());
}// ...
try {
$db->ping();
} catch(\Exception $e) {
exit($e->getMessage());
}// ...
try {
$res = $db->insert("table", $data, \OliverFindl\Database::INSERT_UPDATE);
if($res) $id = $db->lastInsertId();
} catch(\Exception $e) {
exit($e->getMessage());
}
```## Requirements
* [PHP 7](https://secure.php.net/manual/en/install.php)
* [PDO extension](https://secure.php.net/manual/en/pdo.setup.php)## Notes
This class is compliant with selected [PDO::ERR_MODE](http://php.net/manual/en/pdo.setattribute.php).
---
## License
[MIT](http://opensource.org/licenses/MIT)