[英]PHP SQL server 2008 not returning expected results
Hi I am currently developing a php script that will simply return the value of one field. 嗨,我目前正在开发一个PHP脚本,它只返回一个字段的值。 The code below is what ive been using 下面的代码是我一直在使用的
$code = $_POST['code'];
$serverName = "EDIT";
$connectionInfo = array("UID" => "EDIT", "PWD" => "EDIT", "Database"=>"EDIT");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$tsql2 = "SELECT paitentno FROM paraappreg WHERE appno = $code";
$result2 = sqlsrv_query( $conn, $tsql2, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
print sqlsrv_fetch($result2);
This code is generating an output it is however always " 1 ". 此代码生成输出,但始终为“1”。 Im gussing this has something to do with how I am returning the value with sqlsrv_fetch however I am not sure what I should be using if this is the problem. 我在考虑这与我如何使用sqlsrv_fetch返回值有关,但是如果这是问题,我不确定我应该使用什么。
Thanks for any help givin :) 感谢任何帮助givin :)
sqlsrv_fetch "Makes the next row in a result set available for reading." sqlsrv_fetch“使结果集中的下一行可供读取。” The response you are getting is "true" meaning that the operation has succeeded. 您获得的响应是“true”,表示操作已成功。 What you want to do is use one of the variants of this command to get the data (code is not tested but should work): 你想要做的是使用这个命令的一个变体来获取数据(代码未经过测试但应该有效):
print ($result2); // response: 1 ("true")
print_r(sqlsrv_fetch_array($result2)); // response: Array("paitentno"=>'1234');
print_r(sqlsrv_fetch_object($result2)); // response: StdObj->paitentno->1234;
// this gets the item by index:
print_r(sqlsrv_get_field($result2, 0)); // response: 1234;
Read more about sqlsrv_fetch at php.net. 在php.net上阅读有关sqlsrv_fetch的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.