Return ID of inserted record from MS SQL Server Query in PHP -
Return ID of inserted record from MS SQL Server Query in PHP -
i trying homecoming id result query using "output inserted.id". in sql server management studio id of newly inserted row. need homecoming result.
i trying this, know connection working , because making insert table. $value still returns 0.
public function insert($newsql) { $value = '0'; $params = array(array($value,sqlsrv_param_out)); $stmt = sqlsrv_query($this->conn, $newsql, $params); homecoming $value; }
the parameter newsql = "insert test (col1) output inserted.id values ('somevalues')";
for reason $value still returning 0.
figured out.
public function insert($incomingsql) { //append select scope_identity incomingsql $sql = $incomingsql.'; select scope_identity();'; $result = sqlsrv_query($conn,$sql); sqlsrv_next_result($result); sqlsrv_fetch($result); homecoming sqlsrv_get_field($result, 0); }
then phone call
$id = insert("insert table (somecolumn) values ('somevalue)") , $id have lastly inserted id.
php sql-server
Comments
Post a Comment