php sqlsrv_fetch_array() 期望参数 1 是资源,布尔值在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23808512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in
提问by klapsius
im trying print records from my db (IIS, MSSQL PHP) but i have this error...
我正在尝试从我的数据库(IIS、MSSQL PHP)打印记录,但我有这个错误......
Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in
警告:sqlsrv_fetch_array() 期望参数 1 是资源,布尔值在
<?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);
?>
回答by John Conde
Your query failed. This causes sqlsrv_query()
to return false.
您的查询失败。这会导致sqlsrv_query()
返回 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.
仅供参考,您不会检查代码中的错误。您应该始终检查是否出现故障,如果是,请获取错误消息。如果你这样做了,你会很快抓住这个。
回答by Bruno
I have the same problem but look for comma everywhere and nothing!
我有同样的问题,但到处寻找逗号却什么也没有!
if(isset($_POST['login'])) {
co();
$u = addslashes($_POST['username']);
$p = strtoupper(md5($_POST['password']));
$app = 'DanDanTang';
$uid = 0;
$data = array(
array($app, SQLSRV_PARAM_IN),
array($u, SQLSRV_PARAM_IN),
array($p, SQLSRV_PARAM_IN),
array($uid, SQLSRV_PARAM_OUT)
);
$check = sqlsrv_query($conn, "{CALL Mem_Users_Accede (?,?,?,?)}", $data);
/*line 24*/ sqlsrv_next_result($check);
if($uid <= 0)
{
echo '<script type="text/javascript">alert(\'Nome de Usuario ou Senha invalidos\');</script>';
}
else
{