我有一个简单的SELECT语句,一个可选的WHERE子句和一个ORDER BY但是在循环到sqlsrv_fetch_object()时我没有得到任何记录:
if (!$conn)
{
echo "no connection!\n";
}
$data = array();
$qry = "SELECT DISTINCT lineid, ord_num, prod_num, description, prod_type, style, color, sizetype, qty1, qty2, qty3, qty4, qty5, qty6, qty7, qty8, qty9, qty10, qty11, qty12, qty13, qty14, qty15, ext_id, decoration1, design1, iposition1, cccode1, decoration2, design2, iposition2, cccode2, decoration3, design3, iposition3, cccode3, '', design4, iposition4, cccode4, decoration5, design5, iposition5, cccode5, decoration6, design6, iposition6, cccode6, decoration7, design7, iposition7, cccode7, last_mod FROM DataLIVE.dbo.sodetail ";
if ($last_run_date)
{
$qry .= "WHERE last_mod > '" . $last_run_date . "' ";
}
$qry .= "ORDER BY last_mod ASC";
fwrite($fp, $qry . "\n");
if ($st = sqlsrv_query($conn, $qry))
{
while ($row = sqlsrv_fetch_object($st))
{
$row->last_mod = $row->last_mod->format('Y-m-d H:i:s');
fwrite($fp, "Last Mod::: " . $row->last_mod . "\n");
$data[] = $row;
}
sqlsrv_free_stmt($st);
unset($row, $st);
}
else
{
$sqlerr = sqlsrv_errors();
foreach ($sqlerr as $key)
{
foreach ($key as $col => $val)
{
echo "Error Key: " . $col . "\nError Msg: " . $val . "\n";
fwrite($fp, "Error Key: " . $col . "\nError Msg: " . $val . "\n");
}
}
$data = FALSE;
}
return $data;
我不知道为什么sqlsrv_fetch_object()没有返回任何内容。此外,我可以从我正在编写的日志中将查询直接复制并粘贴到SQL Server Studio中,它解析得很好。我的日志文件中没有任何内容我在while循环中写出last_mod日期。
几分钟前我发布了一个略有不同的问题,有人建议删除SELECT语句中空字符串的选择,但是我需要那个空字符串占位符。