I am trying to create a json array in my php mysql script to return to my application. My vendor does not have mysqlnd installed so I am forced to use bind result... below is code that gets my data correctly but I not sure how to fix the data to match the json array id need.
Here is the php code:
$cnt = "";
$empty=array();
$resultArray=array();
$row=array();
$sql =
"select
value as column1,
value2 as column2
from setting where name = ?";
error_log("
sql: " . $sql ,3,"master.log");
if ($stmt = mysqli_prepare($conn, $sql))
{
mysqli_stmt_bind_param($stmt,'s', $sqlvalue1);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$cnt = mysqli_stmt_num_rows($stmt);
error_log("
cnt=? : " . $cnt ,3,"master.log");
if ($cnt == 0)
{
error_log("
cnt=0 : " . $cnt ,3,"master.log");
echo json_encode(array('result'=>$empty));
mysqli_close($conn);
exit;
}
if ($cnt > 0)
{
error_log("
cnt>0 : " . $cnt ,3,"master.log");
$resultArray = array();
$tempArray = array();
mysqli_stmt_bind_result($stmt, $column1, $column2);
while (mysqli_stmt_fetch($stmt))
{
error_log("
while_json 2: " . $column1 . " " . $column2 ,3,"master.log");
//$tempArray = $row;
//array_push($resultArray, $tempArray);
}
echo json_encode(array('result'=>$resultArray));
error_log("
while_json 3: " . print_R($resultArray,TRUE) ,3,"master.log");
mysqli_close($conn);
exit;
}
}
else
{
$resultArray = array(array("success" => "NO", "message" => mysqli_errno($conn) . " " . mysqli_error($conn) , "count" => 0));
echo json_encode(array('success'=>$resultArray));
exit;
}
The json data should look like: (2 Rows returned)
{"result":[{"column1":"0","column2":"VB0023220131"},{"column1":"5","column2":"CE004342420131"}]}
So how do I (in the while loop) create the string above.
thanks. PS the may be multiple row so the