我有這個SQL查詢運行良好,當我在MSSQL管理工作室中執行它,但是當我嘗試在PHP中執行它時,它沒有輸出。從SQL查詢沒有輸出
有什麼建議嗎?
//獲取ID
$atz_id = $_GET['atz_id'];
// SQL查詢
$q2 = "
declare @atzID int set @atzID=$atz_id;
if object_id('tempdb..#vesture1') is not null drop table #vesture1
select distinct
atz_id,
datums s_dat,
cast(NULL as datetime) b_dat,
tips
into #vesture1
from guna..erg2_atzistas_o o
where
darbiba=1
and [email protected]
update #vesture1 set b_dat=(select top 1 datums from guna..erg2_atzistas_o where atz_id=#vesture1.atz_id and darbiba=0 and tips=#vesture1.tips and datums > #vesture1.s_dat order by datums asc)
if object_id('tempdb..#vesture2') is not null drop table #vesture2
select distinct
atz_id,
convert(varchar, s_dat, 104) s_dat,
convert(varchar, b_dat, 104) b_dat,
substring((select ', '+tips from #vesture1 where atz_id=v.atz_id and s_dat=v.s_dat and isnull(b_dat,0)=isnull(v.b_dat,0) order by tips for xml path('')), 3, 3000) 'sugas'
into #vesture2
from #vesture1 v
select * from #vesture2 order by s_dat, b_dat
";
//運行查詢
$res2=mssql_query($q2);
//檢查是否有一些輸出(沒有 - 其他查詢輸出0或行數,這一個不)
$num_rows2 = mssql_num_rows($res2);
echo $num_rows2;
//輸出數據
echo "<table border='1' class='saraksts_table' width='100%' cellspacing='0'>
<tr class='saraksts_header'>
<th><center><font size='1.2px'>info</font></center></th>
<th><center><font size='1.2px'>xxxx</font></center></th>
<th><center><font size='1.2px'>axxa</font></center></th>
<th><center><font size='1.2px'>SAAAa</font></center></th>
</tr>";
while($row2 = mssql_fetch_array($res2))
{
echo "<tr style=background-color:white;>";
echo "<td>" . $row2['atz_id'] . "</td>";
echo "<td>" . $row2['s_dat'] . "</td>";
echo "<td>" . $row2['b_dat'] . "</td>";
echo "<td>" . $row2['sugas'] . "</td>";
echo "</tr>";
}
echo "</table>";
更新 錯誤消息:
PHP Warning: mssql_query(): message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (severity 16) in /home/info/info_pub/sql_vesture.php on line 108
PHP Warning: mssql_query(): General SQL Server error: Check messages from the SQL Server (severity 16) in /home/info/info_pub/sql_vesture.php on line 108
PHP Warning: mssql_num_rows() expects parameter 1 to be resource, boolean given in /home/info/info_pub/sql_vesture.php on line 112
PHP Warning: mssql_fetch_array() expects parameter 1 to be resource, boolean given in /home/info/info_pub/sql_vesture.php on line 167
當你說沒有輸出,你的意思是沒有任何輸出,或只是沒有行? – 2012-01-09 08:24:35
沒有輸出。必須有輸出,但沒有。 查詢在MSSQL管理工作室中工作正常,但是當我嘗試在PHP中執行時,它什麼也沒給我回來。也許在PHP代碼中有一些錯誤,但我找不到任何人 – jeger 2012-01-09 08:27:38
您是否嘗試過輸出插入的行數,分別在#vesture1中更新?你有沒有檢查你的連接字符串 - 你在正確的服務器上,與一個用戶有正確的權利? – 2012-01-09 08:34:17