I have a PHP file that will run a SQL select statement and echo out the results. I am trying to be able to set individual columns to specific variables. Is this possible?
IE: based on the code below, how could I create a variable called $FirstName and set it equal to the value of the single record in the column firstname that is returned?
Thank you
$sql = "SELECT * FROM Employees where Employee_ID = 1";
$stmt = sqlsrv_query( $trpConn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo $row['FirstName'].", ".$row['LastName']."<br />";
}
extract()but that will only lead to problems as you can overwrite existing variables, etc. Even the php manual recommends against using it.$FirstName = $row['FirstName'];before yourechostatement.