my php code,
<?php
header("Content-Type: application/json; charset=UTF-8");
$obj = json_decode($_GET["x"], false);
$serverName = "AE58RETY245YU";
$connectionInfo = array( "Database"=>"Test", "UID"=>"bala",
"PWD"=>"bala");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$outp=array();
$sql = "SELECT Point FROM ".$obj->table."LIMIT".$obj->limit;
$stmt = sqlsrv_query( $conn, $sql );
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$outp=$row['Point'];
}
echo json_encode($outp);
?>
my html code,
<!DOCTYPE html>
<html>
<body>
<h2>Get data as JSON from a PHP file on the server.</h2>
<p>The JSON received from the PHP file:</p>
<p id="demo"></p>
<script>
var obj, dbParam, xmlhttp;
obj = { "table":"PointEvent", "limit":10 };
dbParam = JSON.stringify(obj);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "testsql.php?x=" + dbParam, true);
xmlhttp.send();
</script>
</body>
</html>
Hi ,
Above is my PHP and HTML code,i try to connect sql database using Json(Encode and Decode method) and try to print single column but the error am getting was
'Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in'.
Can anyone please help me with this things.
Thanks in Advance.