반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <?php $host = "localhost"; $user = "id"; $pw = "pw"; $db = "db"; $conn = mysqli_connect($host,$user,$pw,$db); if(mysqli_connect_errno($conn)) { echo "Connect Fail"; } else { $result = mysqli_query($conn,"SELECT * FROM table1 $where"); $arset = array(); while($row = mysqli_fetch_array($result)) { array_push($arset , array('column1'=>$row[0],'column2'=>$row[1],'column3'=>$row[2],'column4'=>$row[3],'column5'=>$row[4])); } $json = my_json_encode(array("result"=>$arset)); echo $json; } mysqli_close($con); //json unicode encoding function my_json_encode($arr) { //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding array_walk_recursive($arr, function (&$item, $key) { if (is_string($item)) $item = mb_encode_numericentity($item, array (0x80, 0xffff, 0, 0xffff), 'UTF-8'); }); return mb_decode_numericentity(json_encode($arr), array (0x80, 0xffff, 0, 0xffff), 'UTF-8'); } ?> | cs |
반응형
'Develop > PHP' 카테고리의 다른 글
[PHP] VSCode 디버그 활성화 (0) | 2021.06.23 |
---|