Good morning,
I have already read the other posts that have similar issues, but nothing is resolving the issue, but bear in mind I am new to the world of PHP and Json. But I am trying to convert a mssql query into json format so that I can then later pass this through google's visualisation api. The query and encoding seems to be working but the encode returns NULL.
I have checked the normal gotcha's of making sure its utf8 encoded and that I have used a version of PHP that has the encode (using php 5.3.19).
Can any one help me with getting the encode to work.
PHP CODE:
<?php
// connection details known to be working fine
if( $conn ) {
echo "Connection established.<br><br>";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$query = "SELECT * FROM tblMetalPrice";
$result = sqlsrv_query( $conn, $query);
while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_NUMERIC) );
$arr = array($result);
$encodedarray = array_map(utf8_encode, $arr);
echo json_encode($encodedarray);
sqlsrv_close( $conn);
?>
When I run this code on the server it comes back with:
Connection established.
[null]
Has anyone got any ideas of getting this to work?
Thanks
Kris