blacktoko / PDO-Databaseclass

Simple PDO Database class

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PDO Database class

Simpel class for PDO beginners. The basic PDO features are Available in this class.

Setup Config

Fill the yaml file as the config example. ```yaml name: database_host: localhost database_name: dbname database_user: root database_password: password ``` The name is the handle name to call the connection.

Setup

* Run composer update to fetch the yaml class. * include the vendor/autoload.php in your php file.

New php classes and files

When you extend this project in your own. Update the psr-4 piece in the composer.json file. After updating and giving the namespaces run ```composer dump-autoload``` to update the autoloader files.

Create connection

```php $database = new Database('handlename'); ``` The connection is setup according to the handle name given with the variables in the config file.

Select one line from database

```php $query = 'SELECT * FROM `table` WHERE `name`=:name LIMIT 1';

$database->query($query); $database->bind(':name', 'John');

$objects = $database->single();


<h2>Select multiple lines from database</h2>
```php
$query = 'SELECT * FROM `table`';

$database->query($query);
$objects = $database->resultset();

Insert into database

```php $query = ' INSERT INTO `table` (`name`, `age`) VALUES (:name, :age)'; $database->query($query); $database->bind(':name', 'John'); $database->bind(':age', 28); $database->execute(); ```

About

Simple PDO Database class


Languages

Language:PHP 100.0%