php - Using Prepare and bind statement try to get JSON data type data from column but it return all column values '0' -
i using mysql 5.7 json properties. added 1 column json datatype. @ time of insertion values added in table prepare,bind mysql statement when try retrieve values json column return 0 values.
//insert
$state_head json associative array [{"state_id":"1","head_id":["1","4"]},{"state_id":"2","head_id":["2"]}] target number $state_head=json_decode($state_head_data,true); for($i=0;$i<count($state_head);$i++) { $stmt = $this->conn->prepare("insert ad_target_network(target_id,state_id,head) values(?,?,?)"); $stmt->bind_param("iis", $target_id,$state_head[$i]["state_id"],json_encode($state_head[$i]['head_id'])); $result=$stmt->execute(); $stmt->close(); }
//select
$state_head=json_decode($state_head_data,true); for($i=0;$i<count($state_head);$i++) { $stmt_select = $this->conn->prepare("select target_network_id,target_id,state_id,head ad_target_network target_id = ? , state_id=?"); $stmt_select->bind_param("ii",$target_id,$state_head[$i]["state_id"]); $stmt_select->bind_result($target_network_id,$target,$state_id,$head); $stmt_select->execute(); $stmt_select->store_result(); if($stmt_select->num_rows > 0) { while($stmt_select->fetch()) { array_push($data,array('target_network_id'=>$target_network_id,'target_id'=>$target,'state_id'=>$state_id,'head'=>$head)); } $response[0] = 1; $response[1] = $data; } $stmt_select->close(); }
please me solve problem...i dont know why can not work.. return column value 0 & null below
//output
{ "target_network_id": 0, "target_id": 0, "state_id": 0, "headend": null }, { "target_network_id": 0, "target_id": 0, "state_id": 0, "headend": null }
but when remove 'head' column $this->conn->prepare(select) & other function bind result & array return ..
{ "target_network_id": 1, "target_id": 2, "state_id": 4, }, { "target_network_id": 2, "target_id": 2 "state_id": 6, }
Comments
Post a Comment