上传包含日期的csv文件,失败。上传csv文件w/o日期,数据保存在db中,但还有另一个错误:-在此结果索引中没有元组可用.
state 22008:我认为是因为它不能读取我的日期格式。我目前的csv格式如下:- 04/02/2017.
是否有方法转换数组中的日期格式?
我尝试在数组中使用"date('d/m/Y',strtotime($dateRecorded))“格式进行转换,但它不起作用。
include('../db_conn.php');
$output = '';
$allowed_ext = array("csv");
$extension = end(explode(".", $_FILES["employee_file"]["name"]));
if(in_array($extension, $allowed_ext))
{
$file_data = fopen($_FILES["employee_file"]["tmp_name"], 'r');
fgetcsv($file_data);
while($row = fgetcsv($file_data))
{
$accnum = addslashes($row[0]);
$dedate = addslashes($row[1]); //deposit date
$transcode = addslashes($row[2]);
$amount = addslashes($row[3]);
$reffno = addslashes($row[4]);
$remarks = addslashes($row[5]);
$query = odbc_exec("INSERT INTO accdetails VALUES( '0','','".$accnum."','".$dedate."','".$transcode."','".$amount."','".$reffno."','".$remarks."','','','','','')");
$result = odbc_fetch_array($query); 我发现了一个错误:-
SQL :InformixInformixNon-日期时间或间隔中的数字字符。
我已经检查了我的insert查询,但是我看不到已经产生了任何多个结果,是因为我的while循环吗?
以前我用过odbc_fetch_array..。但当我在谷歌上搜索时,他们说要用odbc_next_result代替它。但是做了但同样的事情发生了。
$select2 = odbc_exec("SELECT * FROM accdetails ORDER BY spiid ASC");
$result2 = odbc_fetch_array($select2);
$output .= '
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>File Name</th>
<th>Acc No</th>
<th>Depo Date </th>
<th>Trans Code</th>
<th>Amount</th>
<th>Reff No</th>
<th>Remarks</th>
</tr>
';
while($row = odbc_next_result($result2))
{
$output .= '
<tr>
<td>'.$row["spiid"].'</td>
<td>'. $row["spifilename"].'</td>
<td>'.$row["spiaccountno"].'</td>
<td>'.$row["spidepositdate"].'</td>
<td>'.$row["spitranscode"].'</td>
<td>'. $row["spiamount"].'</td>
<td>'.$row["spireferenceno"].'</td>
<td>'.$row["spiremarks"].'</td>
</tr>
';
}
$output .= '</table>';
echo $output;
} 发布于 2019-10-18 09:39:02
MySQL日期应该是格式.
所以你需要改变
$dedate = addslashes($row[1]);通过
$dedate = date( 'Y-m-d H:i:s', $row[1] );希望你能在$row[1]上约会
https://stackoverflow.com/questions/58448020
复制相似问题