该怎么做更新vtiger crm中的可用字段,并在我想上传csv文件时插入新字段?

时间:2013-10-15 06:57:57

标签: php mysql csv crm vtiger

我需要支持基于特定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);

0 个答案:

没有答案