PHP code example of clagiordano / weblibs-dbabstraction

1. Go to this page and download the library: Download clagiordano/weblibs-dbabstraction library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clagiordano / weblibs-dbabstraction example snippets


new PDOAdapter(
    $dbHost,
    $dbUser,
    $dbPassword,
    $dbName,
    $dbDriver,
    $dbCharset,
    $isPersistent
);

/**
 * Class SampleEntity
 */
class SampleEntity extends AbstractEntity
{
}

$entityClass->property = "value";
echo $entityClass->property;

/**
 * Class SampleMapper
 */
class SampleMapper extends AbstractMapper
{

protected $entityTable = 'sample_table';
protected $entityClass = 'SampleEntity';

protected function createEntity(array $fields)
{
    return new SampleEntity(
        [
            'id' => $fields['id'],
            'code' => $fields['code'],
            'brand' => $fields['brand'],
            'model' => $fields['model'],
            'description' => $fields['description']
        ]
    );
}

/**
 * Sample overrided insert method
 *
 * @param SampleEntity $entity
 * @return mixed
 */
public function insert($entity)
{
    if (!$entity instanceof SampleEntity) {
        throw new \InvalidArgumentException(
            __METHOD__ . ": Invalid entity type."
        );
    }

    return $this->adapter->insert($this->entityTable, $entity->toArray());
}