PHP code example of webservco / database

1. Go to this page and download the library: Download webservco/database 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/ */

    

webservco / database example snippets


use WebServCo\Database\Factory\PDOContainerMySQLFactory;

$pdoContainerFactory = new PDOContainerMySQLFactory(
    $configurationGetter->getString('DB_HOST'),
    $configurationGetter->getInt('DB_PORT'),
    $configurationGetter->getString('DB_NAME'),
    $configurationGetter->getString('DB_USER'),
    $configurationGetter->getString('DB_PASSWORD'),
);
// \WebServCo\Database\Contract\PDOContainerInterface
$pdoContainer = $pdoContainerFactory->createPDOContainer();

$stmt = $pdoContainer->getPDOService()->prepareStatement(
    $pdoContainer->getPDO(),
    'SELECT id, name FROM item WHERE user_id = ? LIMIT ?',
);
$stmt->execute([$userId, 50]);

while ($row = $pdoContainer->getPDOService()->fetchAssoc($stmt)) {
    yield $this->hydrateItem($row);
}

use WebServCo\Database\Service\TransactionalDatabaseService;

// \WebServCo\Database\Contract\TransactionalDatabaseServiceInterface
$transactionalDatabaseService = new TransactionalDatabaseService($pdoContainer);
$transactionalDatabaseService->beginTransaction();
// ... queries ...
$transactionalDatabaseService->commitTransaction();