php在SQLSERVER中查询数据出错.求助!!!

来源:百度知道 编辑:UC知道 时间:2024/05/08 02:42:15
大虾们:我的代码如下:

<?php

$conn=mssql_connect("localhost","sa","");

mssql_select_db("fz_oss_database",$conn);

$SqlStr="select serviceid as serviceid from orderusage200901 where ordertime> '2009-01-01 10:00:00' and ordertime<'2009-01-01 10:59:59'";
// $SqlStr="select serviceid from service where servicecode like '1000%'";
echo $SqlStr;
$str = mssql_query($SqlStr);
$row=mssql_num_rows($str);
$row1=mssql_fetch_array($str);

echo "<table border='1'><tr>";
echo "<td></td><td>serviceid</td><td>servicecode</td><td>status</td></tr>";
for ($i=1;$i<=$row;$i++){
//while ($row1){
$row1=mssql_fetch_array($str);
echo "</tr><td>$i</td><td> $row1[0] </td></tr>

输出一下$row试试,看看$row是不是>=1.

你执行了两遍$row1=mssql_fetch_array($str);
第一遍是没有用的。
可能那条语句只有一行结果,你再用$row1=mssql_fetch_array($str); 的时候当然就得不到任何东西了

在你那个有问题的SQL语句中,每个单引号前面加入\,也就是反斜杠,再试试

这个反斜杠与php.ini文件里magic_quotes_gpc选项有关

magic_quotes_gpc = Off

这个默认是关闭的,如果它打开后将自动把用户提交对sql的查询进行转换,比如会自动添加反斜杠