0

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.

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

ohh i missed that. but am still getting the same error on adding too.m updating the question with the change
@user2129794, I have modified my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.