|
|
|
การใช้ array วนอ่านไฟล์ที่มีหลาย field รบกวนช่วยดูให้หน่อยคะว่าเขียนผิดอย่างไร |
|
|
|
|
|
|
|
รบกวนช่วยดูให้หน่อยคะว่าเขียนผิดอย่างไร
Code (PHP)
$objConnect = odbc_connect("mydatabase","","") or die("Error Connect to Database");
$objExec1=odbc_exec($objConnect ,"SELECT * FROM tbl_E");
$num_filed=odbc_num_fields($objExec1);
for($a=1;$a <=$num_filed;$a++){
$FieldNa[$a]=odbc_field_name($objExec1,$a)."</br>";
$dataType[$a]= odbc_field_type($objExec1,$a)."</br>";
}
while(odbc_fetch_row($objExec))
{
$LastRec = odbc_result($objExec,"LastTi") ;
echo"Last record in database is ".$LastRec."</br>";
//$FieldNa=odbc_field_name($objExec1);
}
$fileCSV = "xxxx.csv"
$length = 1000;
$array = file($fileCSV);
for($i=0;$i<count($array);$i++)
{
if ($length < strlen($array[$i]))
{
$length = strlen($array[$i]);
}
}
unset($array);
$handle = fopen($fileCSV, "r");
if(!$handle = fopen($fileCSV, "r"))
{
print 'could not open file. quitting';
die;
}
while(($data = fgetcsv($handle, $length, ",")) != FALSE) {
foreach($data as $key=>$value)
{ $data[$key] = "'" . addslashes($value) . "'";
if(is_numeric($dataType))
{ if($value=""){ $data[$key] = null; }
else{ $data[$key] = "" . addslashes($value) . ""; } }
if($dataType=="DATETIME")
{ $data[$key] = "'" . addslashes($value) . "'"; }
}
$rows[0] = implode(",",$data);
$sql_rr= "";
$sql_rr .= "INSERT INTO tbl_E($FieldNa ) VALUES(";
$sql_rr .= implode("),(", $rows);
$sql_rr .= ")";
}
fclose($handle);
odbc_close($objConnect );
?>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-06-16 07:58:38 |
By :
S-t-A-r |
View :
952 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เข้าใจว่ากำหนดบางอย่างในarray ผิด ช่วยดูให้หน่อยนะคะ
ขอบคุณคะ
|
|
|
|
|
Date :
2010-06-17 15:59:50 |
By :
S-t-A-r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|