[英]Sql server 2008 query php
<?php
$serverName = "brandobti";
$usr="sl";
$pwd="";
$db="SimpleLabel";
$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}
$sql="update products set Nr_Label=0";
$query=sqlsrv_query($conn, $sql);
$result=sqlsrv_fetch_array($query);
print_r($result);
sqlsrv_close( $conn);
I am trying to figure out exactly what I'm doing wrong in this code. 我试图弄清楚我在这段代码中做错了什么。 I know the connection is working correctly;
我知道连接工作正常; I found a script and tested it.
我找到了一个脚本并对其进行了测试。
When I load the PHP page it does nothing at all. 当我加载PHP页面时,它什么也不做。
<?php
$serverName = "brandobti";
$usr="sl";
$pwd="";
$db="SimpleLabel";
$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false)
{
print_r( sqlsrv_errors());
}
$sql="Update products set Nr_Labels=0";
$query = sqlsrv_query($conn, $sql) or die(sqlsrv_errors());
$result=sqlsrv_fetch_array($query);
print_r($result);
sqlsrv_close( $conn);
?>
This is the completed and working code for anyone who is having trouble like i was getting sql to connect, thanks marc b for that i been trying to get this working all day long searching forms so i hope anyone else searching can use this 对于那些遇到麻烦的人(例如我正在连接sql),这是完整的工作代码,谢谢marc b,因为我一直试图整日搜索表单,所以我希望其他人可以使用此功能
You're assuming the query succeeded, and don't have any error handling. 您假设查询成功,并且没有任何错误处理。 If there's a problem with any of those DB calls, they generally return false:
如果这些DB调用中的任何一个出现问题,它们通常返回false:
$query = sqlsrv_query($conn, $sql) or die(sqlsrv_errors());
^^^^^^^^^^^^^^^^^^^^^^^^--- add this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.