我需要支持根据特定 id 更新 vtigercrm 的数据库字段,或者在我想上传 csv 文件时如果没有可用的 id 则插入数据。为此,我创建了 2 个函数,一个是 selectRecords,2 个是 filereader.php 中的 updateDB 和 public function addRecordToDB($columnNames, $fieldValues) { $adb = PearDatabase::getInstance();
$tableName = Import_Utils::getDbTableName($this->user);
$adb->pquery('INSERT INTO '.$tableName.' ('. implode(',', $columnNames).') VALUES ('. generateQuestionMarks($fieldValues) .')', $fieldValues);
$this->numberOfRecordsRead++;
}
//reddy editing
public function selectRecords($columnNames, $fieldValues) {
$adb = PearDatabase::getInstance();
$tableName = Import_Utils::getDbTableName($this->user);
$row = $adb->pquery("select * from vtiger_leadsfc where " .$columnNames[0].='?', array($fieldValues[0]));
$res = $adb->num_rows($row);
return $res;
}
//reddy editing
public function updateDB($columnNames, $fieldValues) {
$adb = PearDatabase::getInstance();
$tableName = Import_Utils::getDbTableName($this->user);
$adb->pquery('UPDATE vtiger_leadsfc SET ('. implode(',', $columnNames).') VALUES ('. generateQuestionMarks($fieldValues) .') WHERE ' .$columnNames[0]."=?", array($fieldValues[0]));
$this->numberOfRecordsRead++;
}
并将此代码添加到 cscreader.php
if($res > 0){$this->updateDB($fieldNames, $fieldValues);}
else
$this->addRecordToDB($fieldNames, $fieldValues);