也许将我的帖子标记为重复,我搜索但找不到我的问题的答案,我已经尝试了所有我看到的其他帖子的答案,但仍然给了我同样的错误:致命错误:致电会员函数format()在非对象中...这是代码:
<?php
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Movimientos Cancelados del Mes.xls"');
header("Pragma: no-cache");
header("Expires: 0");
$server = "192.168.1.240";
$info = array("Database"=>"Ariel","UID"=>"sa","PWD"=>"" );
$conn = sqlsrv_connect($server, $info);
$param = array('ReturnDatesAsStrings'=> true);
$opt = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$per = $_GET["periodo"];
$eje = $_GET["ejercicio"];
$mov = 'Movimiento';
$est = 'Estatus';
$cli = 'Cliente';
$rfc = 'RFC';
$tot = 'Total';
$fec = 'Fecha Timbrado';
$uuid = 'UUID';
$cert = 'Certificado SAT';
$sql = "select v.MovID as '$mov',v.Estatus as '$est',v.Cliente as '$cli',cte.rfc as '$rfc',(v.Importe+v.Impuestos)as '$tot', c.UUID as '$uuid',c.noCertificadoSAT as '$cert', c.FechaTimbrado as '$fec'
from Venta V join CFD c on v.MovID = c.MovID join cte on v.cliente = cte.cliente
where V.Estatus = 'Cancelado' and c.Periodo = '$per' and c.Ejercicio = '$eje' and c.Empresa = 'MGJ'
order by FechaEmision";
var_dump($fec);
$query = sqlsrv_query($conn, $sql);
if( $query === false ) {
if( ($errors = sqlsrv_errors() ) != null) {
foreach( $errors as $error ) {
echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
echo "code: ".$error[ 'code']."<br />";
echo "message: ".$error[ 'message']."<br />";
}
}
}
$campos = sqlsrv_num_fields($query);
$i = 0;
echo "<table border=''><tr>";
echo "<th>$mov</th>";
echo "<th>$est</th>";
echo "<th>$cli</th>";
echo "<th>$rfc</th>";
echo "<th>$tot</th>";
echo "<th>$uuid</th>";
echo "<th>$cert</th>";
while ($row = sqlsrv_fetch_array($query)) {
$mov = $row['Movimiento'];
$est = $row['Estatus'];
$cli = $row['Cliente'];
$rfc = $row['RFC'];
$tot = $row['Total'];
$uuid = $row['UUID'];
$cert = $row['Certificado SAT'];
$fec = $row['Fecha Timbrado'];
echo "<tr>";
echo "<td>".$mov."</td>";
echo "<td>".$est."</td>";
echo "<td>".$cli."</td>";
echo "<td>".$rfc."</td>";
echo "<td>".$tot."</td>";
echo "<td>".$uuid."</td>";
echo "<td>".$cert."</td>";
echo "<td>".$fec->format("d/m/Y")."</td>";
}
echo "</table>";
sqlsrv_close( $conn);
?>
在互联网上查看并查看,但我发现它给了我错误,有趣的是只有一些结果显示错误,有一些如果在屏幕上打印但在一些行后,给出错误它可能在第一次,它可能接近查询的末尾,忽略前几行代码,用于导出到Excel ...错误标记在第75行,即:
echo "<td>".$fec->format("d/m/Y")."</td>";
答案 0 :(得分:0)
发布为社区维基,因为它已在评论中得到解决,并向OP提出了多项建议。
If (! empty($variable)) echo($variable); else echo ('NULL');
是问题的最终解决方案。