Adds a value to the statement in the form of a {@code Value}.
public WithBindVariableValue ( string $key, mixed $value ) : StatementBuilder | ||
$key | string | the value key |
$value | mixed | the value either as a primitive, which will be converted to a PQL Value object, or a PQL Value object |
return | StatementBuilder | a reference to this object |
// relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CustomTargetingService. $customTargetingService = $user->GetService('CustomTargetingService', 'v201508'); // Get all predefined custom targeting keys. $customTargetingKeyIds = getPredefinedCustomTargetingKeyIds($user); // Create a statement to get all custom targeting values for a custom // targeting key. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('customTargetingKeyId = :customTargetingKeyId')->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT); $totalResultsCounter = 0; foreach ($customTargetingKeyIds as $customTargetingKeyId) { // Set the custom targeting key ID to select from. $statementBuilder->WithBindVariableValue('customTargetingKeyId', $customTargetingKeyId); // Default for total result set size and offset. $totalResultSetSize = 0; $statementBuilder->Offset(0); do { // Get custom targeting values by statement. $page = $customTargetingService->getCustomTargetingValuesByStatement($statementBuilder->ToStatement()); // Display results. if (isset($page->results)) { $totalResultSetSize = $page->totalResultSetSize; foreach ($page->results as $customTargetingValue) { printf("%d) Custom targeting value with ID %d, belonging to key with " . "ID %d, name '%s', and display name '%s' was found.\n", $totalResultsCounter++, $customTargetingValue->id, $customTargetingValue->customTargetingKeyId, $customTargetingValue->name, $customTargetingValue->displayName); } } $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT); } while ($statementBuilder->GetOffset() < $totalResultSetSize);
/** * @covers StatementBuilder::WithBindVariableValue */ public function testWithBindingVariable() { $key = 'key'; $value = 'value'; $statementBuilder = new StatementBuilder(); $statementBuilder->WithBindVariableValue($key, $value); $bindVariableMap = $statementBuilder->GetBindVariableMap(); $this->assertEquals($value, $bindVariableMap[$key]->value); }