快速库 delete_record
Quickbase delete_record
我无法使 delete_record 功能正常工作。这是我目前使用的 delete_record 代码:
$qb->db_id = $myQbTables["table1"]; //using table 1 now
$queries = array( //this is the where clause now for the delete query
array(
'fid' => '12',
'ev' => 'EX',
'cri' => '1175'
),
array(
'fid' => '8',
'ev' => 'EX',
'cri' => $Child_ID
)
);
$results = $qb->do_query($queries, '', '', 'a', '1', 'structured', 'sortorder-A'); //get all results
if($results->errCode !== 0) {
echo $results->errTxt;
}
print_r($results);
foreach($results->table->records->record as $record){ //getting results of delete query
$Deletevar = $record->f[11];
$deleted = $qb->delete_record($Deletevar); //deleting results
print_r($deleted);
}
我知道 'cri' 与我的 quickbase 中的内容匹配,但我似乎无法使用 f[3](记录 ID)删除它!
注意
我找到了我遇到的主要问题!如果您使用 QB API 进行 API 调用,删除记录和清除记录不包括应用令牌!!请使用以下代码更新 delete_records 函数!!!!
public function delete_record($rid) {
if($this->xml) {
$xml_packet = new SimpleXMLElement('<qdbapi></qdbapi>');
$xml_packet->addChild('rid',$rid);
$xml_packet->addChild('ticket',$this->ticket);
$xml_packet->addChild('apptoken',$this->app_token);
$xml_packet = $xml_packet->asXML();
$response = $this->transmit($xml_packet, 'API_DeleteRecord');
}
else {
$url_string = $this->qb_ssl . $this->db_id. "?act=API_DeleteRecord&ticket=". $this->ticket
."&apptoken=".$this->app_token."&rid=".$rid;
$response = $this->transmit($url_string);
}
return $response;
}
我认为您的查询中可能遗漏了一些内容。如果您尝试获取字段 12 为 1157 且字段 8 等于 $Child_ID
的记录列表,您需要将 AND
添加到查询中。在 URL 中使用 API 时,如果子 ID 为 77,则查询将是 &query={12.EX.1175}AND{8.EX.77}
。要在 PHP SDK for Quickbase 中执行此操作,您可以添加'ao' => 'AND'
到第一个查询数组之后的所有数组。尝试将您的 $queries 数组更新为:
$queries = array( //this is the where clause now for the delete query
array(
'fid' => '12',
'ev' => 'EX',
'cri' => '1175'
),
array(
'ao' => 'AND', // Saying that 12.EX.1175 AND 8.EX.$Child_ID
'fid' => '8',
'ev' => 'EX',
'cri' => $Child_ID
)
);
我的 PHP 技能不是特别好,但您需要做更多的工作才能获得记录 ID#。在原始代码中,我认为 $record->f[3]
只会 return 到数组中第三个字段的 SimpleXMLObject。这不一定是字段 ID 3(记录 ID)。您可以选择不使用结构化格式(并更改所有代码以匹配)或添加一个循环遍历所有字段并在到达 ID 为 3 的字段时删除:
foreach($results->table->records->record as $record){ //getting results of delete query
//Loop through all fields to find id 3
foreach($record->f as $field){
if($field['id'] == "3"){
$Deletevar = $field['id'];
$deleted = $qb->delete_record($Deletevar); //deleting result
print_r($deleted);
break; //Stops this loop since FID 3 was found
}
}
}
一些性能说明:如果您没有使用任何其他字段,您可以通过传递一个仅为“3”的列表将查询设置为仅 return 记录 ID。此外,每个 delete_record()
都是一个单独的 API 调用。还有另一种方法 purge_records
允许您传递查询,Quickbase 会删除所有与您的查询匹配的记录。您可能需要考虑使用 purge_records()
,因为您可以使用它代替 do_query()
并避免所有循环。它使用更少的资源和 Quickbase 的资源来处理。
我无法使 delete_record 功能正常工作。这是我目前使用的 delete_record 代码:
$qb->db_id = $myQbTables["table1"]; //using table 1 now
$queries = array( //this is the where clause now for the delete query
array(
'fid' => '12',
'ev' => 'EX',
'cri' => '1175'
),
array(
'fid' => '8',
'ev' => 'EX',
'cri' => $Child_ID
)
);
$results = $qb->do_query($queries, '', '', 'a', '1', 'structured', 'sortorder-A'); //get all results
if($results->errCode !== 0) {
echo $results->errTxt;
}
print_r($results);
foreach($results->table->records->record as $record){ //getting results of delete query
$Deletevar = $record->f[11];
$deleted = $qb->delete_record($Deletevar); //deleting results
print_r($deleted);
}
我知道 'cri' 与我的 quickbase 中的内容匹配,但我似乎无法使用 f[3](记录 ID)删除它!
注意
我找到了我遇到的主要问题!如果您使用 QB API 进行 API 调用,删除记录和清除记录不包括应用令牌!!请使用以下代码更新 delete_records 函数!!!!
public function delete_record($rid) {
if($this->xml) {
$xml_packet = new SimpleXMLElement('<qdbapi></qdbapi>');
$xml_packet->addChild('rid',$rid);
$xml_packet->addChild('ticket',$this->ticket);
$xml_packet->addChild('apptoken',$this->app_token);
$xml_packet = $xml_packet->asXML();
$response = $this->transmit($xml_packet, 'API_DeleteRecord');
}
else {
$url_string = $this->qb_ssl . $this->db_id. "?act=API_DeleteRecord&ticket=". $this->ticket
."&apptoken=".$this->app_token."&rid=".$rid;
$response = $this->transmit($url_string);
}
return $response;
}
我认为您的查询中可能遗漏了一些内容。如果您尝试获取字段 12 为 1157 且字段 8 等于 $Child_ID
的记录列表,您需要将 AND
添加到查询中。在 URL 中使用 API 时,如果子 ID 为 77,则查询将是 &query={12.EX.1175}AND{8.EX.77}
。要在 PHP SDK for Quickbase 中执行此操作,您可以添加'ao' => 'AND'
到第一个查询数组之后的所有数组。尝试将您的 $queries 数组更新为:
$queries = array( //this is the where clause now for the delete query
array(
'fid' => '12',
'ev' => 'EX',
'cri' => '1175'
),
array(
'ao' => 'AND', // Saying that 12.EX.1175 AND 8.EX.$Child_ID
'fid' => '8',
'ev' => 'EX',
'cri' => $Child_ID
)
);
我的 PHP 技能不是特别好,但您需要做更多的工作才能获得记录 ID#。在原始代码中,我认为 $record->f[3]
只会 return 到数组中第三个字段的 SimpleXMLObject。这不一定是字段 ID 3(记录 ID)。您可以选择不使用结构化格式(并更改所有代码以匹配)或添加一个循环遍历所有字段并在到达 ID 为 3 的字段时删除:
foreach($results->table->records->record as $record){ //getting results of delete query
//Loop through all fields to find id 3
foreach($record->f as $field){
if($field['id'] == "3"){
$Deletevar = $field['id'];
$deleted = $qb->delete_record($Deletevar); //deleting result
print_r($deleted);
break; //Stops this loop since FID 3 was found
}
}
}
一些性能说明:如果您没有使用任何其他字段,您可以通过传递一个仅为“3”的列表将查询设置为仅 return 记录 ID。此外,每个 delete_record()
都是一个单独的 API 调用。还有另一种方法 purge_records
允许您传递查询,Quickbase 会删除所有与您的查询匹配的记录。您可能需要考虑使用 purge_records()
,因为您可以使用它代替 do_query()
并避免所有循环。它使用更少的资源和 Quickbase 的资源来处理。