PHP code example of makinacorpus / goat-query
1. Go to this page and download the library: Download makinacorpus/goat-query 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/ */
makinacorpus / goat-query example snippets
$driver = \Goat\Driver\DriverFactory::fromUri('pgsql://username:password@hostname:5432/database?option1=value1&option2=value2');
$driver = new \Goat\Driver\ExtPgSQLDriver();
$driver->setConfiguration(
\Goat\Driver\Configuration::fromString(
'pgsql://username:password@hostname:5432/database?option1=value1&option2=value2'
)
);
$runner = $driver->getRunner();
$platform = $runner->getPlatform();
$queryBuilder = $runner->getQueryBuilder();
if ($platform->supportsReturning()) {
$result = $queryBuilder
->insertValues('users')
->columns(['id', 'name'])
->values([1, 'Jean'])
->values([1, 'Robert'])
->returning('*')
->setOption('class', \App\Domain\Model\User::class)
->execute()
;
} else {
$queryBuilder
->insertValues('users')
->columns(['id', 'name'])
->values([1, 'Jean'])
->values([2, 'Robert'])
->execute()
;
$result = $queryBuilder
->select('users')
->where('id', [1, 2])
->setOption('class', \App\Domain\Model\User::class)
->execute()
}
foreach ($result as $user) {
\assert($user instanceof \App\Domain\Model\User);
echo "Hello, ", $user->getName(), " !\n";
}