PHP code example of teddybear06 / edgedb-php
1. Go to this page and download the library: Download teddybear06/edgedb-php 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/ */
teddybear06 / edgedb-php example snippets
// Require Composer's autoloader
yBear06\EdgeDbPhp\EdgeDbHttpClient;
use TeddyBear06\EdgeDbPhp\EdgeQlQuery;
// Establish a connection with the EdgeDB server instance
$connection = new EdgeDbHttpClient('127.0.0.1', '10700', 'edgedb');
// Create an EdgeQL query
$query = new EdgeQlQuery(
'select Author {firstname, lastname} filter .lastname = <str>$lastname;',
['lastname' => 'Doe']
);
// Execute the query
$response = $connection->query($query);
// If there is no error message
if (is_null($response->getError())) {
// If there is at least 1 result
if ($response->countData() > 0) {
// Loop over results
foreach ($response->getData() as $data) {
echo $data['firstname'];
}
} else {
// Data set is empty
echo 'No matches found...';
}
} else {
// Call $response->getError() to get error details
// message, type or code array indexes are available
echo $response->getError()['message'];
}
bash
$ composer