PHPackages                             visma-dev/db-class - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. visma-dev/db-class

ActiveLibrary[Database &amp; ORM](/categories/database)

visma-dev/db-class
==================

01PHP

Since Mar 31Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Visma-Dev/dbClass)[ Packagist](https://packagist.org/packages/visma-dev/db-class)[ RSS](/packages/visma-dev-db-class/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

dbClass
=======

[](#dbclass)

The library implements additional validation of values in order to make an already good and safe product even better and even safer.

```
/**
* Query Initialization
*
* @param string $query
* @param array $parameters
* @return void
*/
private function init(string $query, array $parameters = [])
{
   // check the property for connection
   if (!$this->isConnected) {
       $this->connection();
   }

   try {
       //Preparing the query
       $this->statement = $this->pdo->prepare($query);

       //Binding parameters
       $this->bind($parameters);

       if (!empty($this->parameters)) {
           foreach ($this->parameters as $param => $value) {

               //setting data types for our params
               if (is_int($value[1])) {
                   $type = \PDO::PARAM_INT;
               }elseif (is_bool($value[1])) {
                   $type = \PDO::PARAM_BOOL;
               }elseif (is_string($value[1])) {
                   $type = \PDO::PARAM_STR;
               }else {
                   $type = \PDO::PARAM_NULL;
               }
               $this->statement->bindValue($value[0], $value[1], $type);

           }
       }
       //execute the query
       $this->statement->execute();

   }catch (\PDOException $e) {
       exit($e->getMessage());
   }

   // cleaning the parameters property after execution
   $this->parameters = [];
}
```

While working on this project, I gained new practical (as well as theoretical) knowledge in working with:
---------------------------------------------------------------------------------------------------------

[](#while-working-on-this-project-i-gained-new-practical-as-well-as-theoretical-knowledge-in-working-with)

- #### pdo;

    [](#pdo)
- #### composer;

    [](#composer)
- #### packagist;

    [](#packagist)
- #### strict typing;

    [](#strict-typing)
- #### commenting (DocBlock);

    [](#commenting-docblock)
- #### regex;

    [](#regex)

How to use:
-----------

[](#how-to-use)

1. Use this command to install the package

```
 composer require visma-dev/db-class:@dev
```

2. Connect the autoload.php and import the class

```
  require_once __DIR__ . '/vendor/autoload.php';

  use Visma\dbClass\Database;
```

Usage examples
--------------

[](#usage-examples)

### Select

[](#select)

```
