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


PHP getImportCVSFields函数代码示例

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


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

示例1: ImportFromCSV

function ImportFromCSV($uploadfile)
{
    $ret = 1;
    global $error_message, $keys, $goodlines, $total_records, $conn, $strOriginalTableName, $keys_present, $auditObj;
    $fields = array();
    $fields = getImportCVSFields($uploadfile);
    // populate field names array
    for ($j = 0; $j < count($fields); $j++) {
        $fields[$j] = trim($fields[$j]);
        if (substr($fields[$j], 0, 1) == "\"" && substr($fields[$j], -1) == "\"") {
            $fields[$j] = substr($fields[$j], 1, -1);
        }
    }
    $fields = getFieldNamesByHeaders($fields);
    $keys_present = 1;
    for ($k = 0; $k < count($keys); $k++) {
        if (!in_array(RemoveFieldWrappers($keys[$k]), $fields)) {
            $keys_present = 0;
            break;
        }
    }
    $autoinc = false;
    if (in_array("Record ID", $fields)) {
        $autoinc = true;
    }
    if ($autoinc) {
        $sql = "SET IDENTITY_INSERT " . AddTableWrappers($strOriginalTableName) . " ON";
        db_exec($sql, $conn);
    }
    $total_records = 0;
    $line = "";
    $row = 0;
    // parse records from file
    if (($handle = fopen($uploadfile, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000000, ",")) !== FALSE) {
            // first rec contain only fields names
            if ($row === 0) {
                $row++;
                continue;
            }
            $arr = array();
            foreach ($data as $key => $val) {
                $type = GetFieldType($fields[$key]);
                if (IsDateFieldType($type)) {
                    $value = localdatetime2db($val);
                    if ($value !== -1 && $value !== FALSE && strlen($value)) {
                        $arr[$fields[$key]] = $value;
                    } else {
                        $arr[$fields[$key]] = NULL;
                    }
                } elseif (IsTimeType($type)) {
                    $value = localtime2db($val);
                    if ($value !== -1 && $value !== FALSE && strlen($value) && strlen($val) && !is_null($val)) {
                        $arr[$fields[$key]] = $value;
                    } else {
                        $arr[$fields[$key]] = NULL;
                    }
                } else {
                    $arr[$fields[$key]] = $val;
                }
            }
            $ret = InsertRecord($arr, $row);
            $row++;
        }
        fclose($handle);
    }
    $total_records = $row - 1;
    if ($autoinc) {
        $sql = "SET IDENTITY_INSERT " . AddTableWrappers($strOriginalTableName) . " OFF";
        db_exec($sql, $conn);
    }
    return $ret;
}
开发者ID:samsulpendis,项目名称:Instant_Appointment,代码行数:73,代码来源:Readings_import.php

示例2: ImportFromCSV

function ImportFromCSV($uploadfile, $strOriginalTableName, $ext, $keys, &$keys_present, &$total_records, &$error_message, &$goodlines, $pageObject, $cipherer)
{	
	global $conn, $gSettings;

	$ret = 1;

	$fields = array();
	
	$fields = getImportCVSFields($uploadfile);
	
	// populate field names array
	for ($j=0;$j<count($fields);$j++)
	{
		$fields[$j] = $fields[$j];
		if(substr($fields[$j],0,1)=="\"" && substr($fields[$j],-1)=="\"")
			$fields[$j]=substr($fields[$j],1,-1);
	}
	$fields = getFieldNamesByHeaders($fields, $strOriginalTableName, $ext);

	if($fields == null) // if error happened
		return;
	
	$keys_present=1;
	for($k=0; $k<count($keys); $k++)
	{
		if (!in_array(RemoveFieldWrappers($keys[$k]),$fields))
		{
			$keys_present=0;
			break;
		}
	}
	$autoinc = false;
		if(in_array("id",$fields))
		$autoinc=true;
				
		
	
	
	if(GetDatabaseType() == 2 && $autoinc)
{
	$sql="SET IDENTITY_INSERT ".AddTableWrappers($strOriginalTableName)." ON";
	db_exec($sql,$conn);
}
$total_records = 0;
	$line = "";		
	$row = 0;
	// parse records from file
	if (($handle = OpenCSVFile($uploadfile)) !== FALSE) 
	{
	    while (($data = GetCSVLine($handle, 1000000, ",")) !== FALSE) 
	    {
	    				// first rec contain only fields names	    	
	    	if ($row === 0)
	    	{
	    		$row++;
	    		continue;	    		
	    	}
	    	$arr = array();
			foreach($data as $key=>$val)
			{
				$type = $gSettings->getFieldType($fields[$key]);
				if(IsDateFieldType($type))
				{
					$value = localdatetime2db($val);
					if ( $value !== FALSE && strlen($value) && $value != 'null' )
						$arr[$fields[$key]] = $value;
					else
						$arr[$fields[$key]] = NULL;
				}
				elseif(IsTimeType($type))
				{
					$value = localtime2db($val);
					if ( $value !== FALSE && strlen($value) && !is_null($val) && strlen($val) )
						$arr[$fields[$key]] = $value;
					else
						$arr[$fields[$key]] = NULL;
				}
				else
					$arr[$fields[$key]] = $val;
			}
			
	    	$ret = InsertRecord($arr, $row, $error_message, $goodlines, $keys, $keys_present, 
	    		$strOriginalTableName, $pageObject, $cipherer, $autoinc);
	        $row++;
	    }
	    CloseCSVFile($handle);
	}
	
$total_records = $row-1;
if(GetDatabaseType() == 2 && $autoinc)
{
	$sql="SET IDENTITY_INSERT ".AddTableWrappers($strOriginalTableName)." OFF";
	db_exec($sql,$conn);
}
	
	
	
		
	return $ret;	
} 
开发者ID:helbertfurbino,项目名称:sgmofinanceiro,代码行数:100,代码来源:webreport_users_import.php


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