PHP code example of nieknijland / rdw-opendata-php
1. Go to this page and download the library: Download nieknijland/rdw-opendata-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/ */
nieknijland / rdw-opendata-php example snippets
use NiekNijland\RDW\Rdw;
use NiekNijland\RDW\Fields\RegisteredVehicleField;
use NiekNijland\RDW\Query\SortDirection;
$rdw = new Rdw();
$vehicles = $rdw->registeredVehicles()
->where(RegisteredVehicleField::CommercialName, 'POLO')
->where(RegisteredVehicleField::CanBeTransferred, true)
->orderBy(RegisteredVehicleField::RegistrationDate, SortDirection::Desc)
->limit(10)
->get();
foreach ($vehicles as $vehicle) {
echo $vehicle->licensePlate.' '.$vehicle->brand.' '.$vehicle->commercialName.PHP_EOL;
echo ' registered: '.$vehicle->registrationDate?->toDateString().PHP_EOL;
echo ' apk: '.$vehicle->apkExpiryDate?->toDateString().PHP_EOL;
}
use NiekNijland\RDW\Rdw;
use NiekNijland\RDW\Http\Configuration;
$rdw = new Rdw(new Configuration(
appToken: 'YOUR_SOCRATA_APP_TOKEN', // optional, raises your rate limit
userAgent: 'your-app/1.0',
timeoutSeconds: 10.0,
));
// Raw row fetch. The $query map is passed through to Socrata as-is.
$rows = $rdw->rawRows(DatasetId::RegisteredVehicles, [
'$where' => "kenteken = 'AB-12-CD'",
'$select' => 'kenteken, merk, handelsbenaming',
]);
// Raw metadata document (column types, descriptions, last update, …).
$meta = $rdw->rawMetadata(DatasetId::RegisteredVehicles);
foreach ($rdw->registeredVehicles()
->where(RegisteredVehicleField::Brand, 'VOLKSWAGEN')
->iterate(pageSize: 1000) as $vehicle) {
// process one vehicle at a time without buffering the whole set
}
foreach ($rdw->registeredVehicles()
->where(RegisteredVehicleField::Brand, 'VOLKSWAGEN')
->iterate(pageSize: 1000) as $vehicle) {
// one row at a time, no buffering
}