Reputation: 2418
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.
Upvotes: 0
Views: 3895
Reputation: 5179
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.
Upvotes: 1