我无法使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;
}
答案 0 :(得分:1)
我认为您的查询中可能遗漏了一些内容。如果您要获取字段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]
将返回到数组中第三个字段的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”的clist来返回记录ID。此外,每个delete_record()
都是一个单独的API调用。还有另一种方法purge_records
允许您传递查询,Quickbase会删除与您的查询匹配的所有记录。您可能希望使用purge_records()
,因为您可以使用它代替do_query()
并避免所有循环。它使用较少的资源和Quickbase来处理。