sqlsrv_fetch_array()期望参数1为资源,布尔值在 [英] sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in

查看:257
本文介绍了sqlsrv_fetch_array()期望参数1为资源,布尔值在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的数据库(IIS,MSSQL PHP)中打印记录,但是我遇到此错误...

im trying print records from my db (IIS, MSSQL PHP) but i have this error...

警告:sqlsrv_fetch_array()期望参数1为资源,布尔值在其中提供

Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in

<?php

$serverName ="name\SQLEXPRESS";
 $usr="sa";
 $pwd="pasw";
 $db="dbname";

$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);

$conn = sqlsrv_connect($serverName, $connectionInfo);



  $sql = "SELECT first_col, s_col, t_col,  FROM names ";
 $res = sqlsrv_query($conn,$sql);
  while ($row = sqlsrv_fetch_array($res)) {
    print(
    $row['first_col'].",".$row['s_col'].",".$row['t_col'].");

 }  


sqlsrv_close( $conn); 
?>

推荐答案

您的查询失败.这会导致sqlsrv_query()返回false.

Your query failed. This causes sqlsrv_query() to return false.

您的查询错误是一个错误的逗号:

Your error in your query is an errant comma:

$sql = "SELECT first_col, s_col, t_col,  FROM names ";
                                    ^^^^
                                    HERE

将其删除,您的查询应该可以正常工作.

Remove it and your query should work.

仅供参考,您无需检查代码中的错误.您应该始终检查是否有失败,如果失败,则获取错误消息.如果这样做的话,您很快就会发现这一点.

FYI, you don't check for errors in your code. You should always check to see if something failed, and if so, get the error message. You would have caught this quickly if you did.

这篇关于sqlsrv_fetch_array()期望参数1为资源,布尔值在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆