簡體   English   中英

致命錯誤:在非對象中調用成員函數format()

[英]Fatal error: Call to a member function format() on a non-object in

也許將我的帖子標記為重復,我搜索但找不到我的問題的答案,我已經嘗試了所有我看到的其他帖子的答案,但仍然給了我同樣的錯誤:致命錯誤:調用成員函數格式( )在一個非對象中...這是代碼:

<?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>";

發布為社區維基,因為它在評論中得到了解決,並向OP提出了多項建議。

If (! empty($variable)) echo($variable); else echo ('NULL');

是問題的最終解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM