简体   繁体   中英

SELECT operation using sqlsrv_query in php

I am using following php code to select a max value from a table in MS sql server database. This is just a snapshot of the code and not full code:

$sqlToCheckNID ="Select (?)=max(nid) from testRetailerlist";
$param_nid = array($maxNid,SQLSRV_PARAM_OUT);   
$maxNidInDb = sqlsrv_query($conn,$sqlToCheckNID,$param_nid); 
  echo "<li>" .$maxNid. "<li>";

Its throwing me error as Undefined variable maxNid

I want to echo the value that i get from the select statement. I think I am using the wrong syntax but could not found any example on net.

You need to add your parameters' array as a third argument to sqlsrv_query() . You should also pass the output parameters by reference after initializing them. So your your code would be like this:

$maxNid = 0;
$sqlToCheckNID = "SELECT (?)=MAX(nid) FROM testRetailerlist";
$param_nid = array(&$maxNid, SQLSRV_PARAM_OUT);   
$maxNidInDb = sqlsrv_query($conn, $sqlToCheckNID, $param_nid);
echo "<li>" .$maxNid. "<li>";

For more information please consult the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM