当前位置: 首页>>代码示例>>PHP>>正文


PHP GetKeysArray函数代码示例

本文整理汇总了PHP中GetKeysArray函数的典型用法代码示例。如果您正苦于以下问题:PHP GetKeysArray函数的具体用法?PHP GetKeysArray怎么用?PHP GetKeysArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetKeysArray函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: InsertRecord

function InsertRecord($arr, $recInd)
{
    global $goodlines, $conn, $error_message, $keys_present, $keys, $strOriginalTableName, $strTableName, $eventObj, $locale_info, $auditObj;
    $ret = 1;
    $rawvalues = array();
    foreach ($arr as $key => $val) {
        $rawvalues[$key] = $val;
        $type = GetFieldType($key);
        if (!NeedQuotes($type)) {
            $value = (string) $val;
            $value = str_replace(",", ".", $value);
            if (strlen($value) > 0) {
                $value = str_replace($locale_info["LOCALE_SCURRENCY"], "", $value);
                $arr[$key] = 0 + $value;
            } else {
                $arr[$key] = NULL;
            }
        }
    }
    $retval = true;
    if ($eventObj->exists('BeforeInsert')) {
        $retval = $eventObj->BeforeInsert($rawvalues, $arr);
    }
    if ($retval) {
        $fields = array_keys($arr);
        foreach ($fields as $key => $val) {
            $fields_list[$key] = AddFieldWrappers(GetFullFieldName($val));
        }
        $values_list = "";
        foreach ($arr as $key => $val) {
            if (!is_null($arr[$key])) {
                $values_list .= add_db_quotes($key, $val) . ", ";
            } else {
                $values_list .= "NULL, ";
            }
        }
        if (strlen($values_list) > 0) {
            $values_list = substr($values_list, 0, strlen($values_list) - 2);
        }
        $sql = "insert into " . AddTableWrappers($strOriginalTableName) . " (" . implode(",", $fields_list) . ") values (" . $values_list . ")";
        if (db_exec_import($sql, $conn)) {
            $goodlines++;
            if ($auditObj) {
                $aKeys = GetKeysArray($arr, true);
                $auditObj->LogAdd($strTableName, $arr, $aKeys);
            }
        } else {
            $temp_error_message = "<b>Error:</b> in the line: " . implode(",", $arr) . '&nbsp;&nbsp;<a linkType="debugOpener" recId="' . $recInd . '" href="" onclick="importMore(' . $recInd . ');">More info</a><br>';
            $temp_error_message .= '<div id="importDebugInfoTable' . $recInd . '" cellpadding="3" cellspacing="1" align="center" style="display: none;"><p class="error">SQL query: ' . $sql . '; </p><p class="error">DB error: ' . db_error($conn) . ';</p></div>';
            $temp_error_message .= "<br><br>";
            // we'll try to update the record
            if ($keys_present) {
                $sql = "update " . AddTableWrappers($strOriginalTableName) . " set ";
                $sqlset = "";
                $where = " where ";
                foreach ($fields as $k => $val) {
                    if (!in_array(AddFieldWrappers($fields[$k]), $keys)) {
                        if (!is_null($arr[$val])) {
                            $sqlset .= $fields_list[$k] . "=" . add_db_quotes($val, $arr[$val]) . ", ";
                        } else {
                            $sqlset .= $fields_list[$k] . "=NULL, ";
                        }
                    } else {
                        $where .= $fields_list[$k] . "=" . add_db_quotes($val, $arr[$val]) . " and ";
                    }
                }
                if (strlen($sqlset) > 0) {
                    $sql .= substr($sqlset, 0, strlen($sqlset) - 2);
                }
                $where = substr($where, 0, strlen($where) - 5);
                $sql .= " " . $where;
                $rstmp = db_query("select * from " . AddTableWrappers($strOriginalTableName) . " " . $where, $conn);
                $data = db_fetch_array($rstmp);
                if ($data) {
                    if ($auditObj) {
                        foreach ($data as $key => $val) {
                            $auditOldValues[$key] = $val;
                        }
                    }
                    if (db_exec_import($sql, $conn)) {
                        // update successfull
                        $goodlines++;
                        if ($auditObj) {
                            $aKeys = GetKeysArray($arr);
                            $auditObj->LogEdit($strTableName, $arr, $auditOldValues, $aKeys);
                        }
                    } else {
                        echo 'not updated';
                        // update not successfull
                        $error_message .= $temp_error_message;
                        $ret = 0;
                    }
                } else {
                    $error_message .= $temp_error_message;
                    $ret = 0;
                }
            } else {
                $error_message .= $temp_error_message;
            }
        }
//.........这里部分代码省略.........
开发者ID:samsulpendis,项目名称:Instant_Appointment,代码行数:101,代码来源:Readings_import.php

示例2: importRecord

 /**
  * Insert an imported record to the database
  * @param Array fieldsValuesData			An array having the import fields names as 'keys' and the corresponding fields' values as 'values'
  * @param Array keys						The key fields' names
  * @param Boolean isIdentityOffNeeded		The flag indicating if there is any autoincremented import field
  * @param &Number addedRecords
  * @param &Number updatedRecords
  * @param &Array errorMmessages	 
  * @param &Array unprocessedData
  */
 public function importRecord($fieldsValuesData, $keys, $isIdentityOffNeeded, &$addedRecords, &$updatedRecords, &$errorMessages, &$unprocessedData)
 {
     $rawvalues = $fieldsValuesData;
     $fieldsValuesData = $this->prepareFiledsValuesData($fieldsValuesData);
     if ($this->eventsObject->exists('BeforeInsert')) {
         if ($this->eventsObject->BeforeInsert($rawvalues, $fieldsValuesData, $this) === false) {
             return;
         }
     }
     $fieldNames = array_keys($fieldsValuesData);
     // try to insert the record
     $sql = $this->getInsertSQL($fieldNames, $fieldsValuesData);
     if (db_exec_import($sql, $this->connection, $this->connection->addTableWrappers($this->strOriginalTableName), $isIdentityOffNeeded)) {
         $addedRecords = $addedRecords + 1;
         if ($this->audit) {
             $this->audit->LogAdd($this->tName, $fieldsValuesData, GetKeysArray($fieldsValuesData, $this, true));
         }
         return;
     }
     $tempErrorMessage = $this->connection->lastError();
     $keyFieldsNames = array_intersect($fieldNames, $keys);
     if (!$keyFieldsNames) {
         if (!count($unprocessedData)) {
             $unprocessedData[] = $this->getImportFieldsLogCSVLine($fieldNames);
         }
         $unprocessedData[] = $this->parseValuesDataInLogCSVLine($fieldsValuesData);
         $errorMessages[] = $tempErrorMessage;
         return;
     }
     // try to update the record
     $updateWhere = $this->getUpdateSQLWhere($keyFieldsNames, $fieldsValuesData);
     $getAllUpdatedSQL = "select * from " . $this->connection->addTableWrappers($this->strOriginalTableName) . " where " . $updateWhere;
     $data = $this->connection->query($getAllUpdatedSQL)->fetchAssoc();
     if ($data) {
         $notKeyFieldsNames = array_diff($fieldNames, $keys);
         $sql = $this->getUpdateSQL($notKeyFieldsNames, $fieldsValuesData, $updateWhere);
         if (db_exec_import($sql, $this->connection, $this->connection->addTableWrappers($this->strOriginalTableName), $isIdentityOffNeeded)) {
             // update successfull
             $updatedRecords = $updatedRecords + 1;
             if ($this->audit) {
                 $auditOldValues = array();
                 foreach ($data as $key => $val) {
                     $auditOldValues[$key] = $val;
                 }
                 $this->audit->LogEdit($this->tName, $fieldsValuesData, $auditOldValues, GetKeysArray($fieldsValuesData, $this));
             }
         } else {
             // update not successfull
             if (!count($unprocessedData)) {
                 $unprocessedData[] = $this->getImportFieldsLogCSVLine($fieldNames);
             }
             $unprocessedData[] = $this->parseValuesDataInLogCSVLine($fieldsValuesData);
             $errorMessages[] = $this->connection->lastError();
         }
     } else {
         if (!count($unprocessedData)) {
             $unprocessedData[] = $this->getImportFieldsLogCSVLine($fieldNames);
         }
         // nothing to update
         $unprocessedData[] = $this->parseValuesDataInLogCSVLine($fieldsValuesData);
         $errorMessages[] = $tempErrorMessage;
     }
 }
开发者ID:ryanblanchard,项目名称:Dashboard,代码行数:73,代码来源:importpage.php


注:本文中的GetKeysArray函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。