Codit Develop
Codit Develop
Codit Develop
전체 방문자
오늘
어제
  • 분류 전체보기 (146)
    • IT (1)
      • 스마트폰 (1)
    • Game (59)
      • DNF (0)
      • StarCraft2 (11)
      • LostArk (45)
      • Minecraft (3)
      • Elyon (0)
    • Develop (43)
      • Web (15)
      • PHP (2)
      • Laravel (0)
      • C# (11)
      • NodeJS (1)
      • Java (2)
      • Python (1)
      • Cordova (3)
      • Android (0)
      • WPF (1)
      • PowerShell (5)
      • Other (2)
      • Javascript (0)
    • OS (17)
      • Windows (6)
      • Linux (11)
    • Product (17)
      • Docker (10)
      • GitLab (3)
      • NuGet (2)
      • Git (1)
      • Nginx (1)
    • DB (7)
      • All-DB (2)
      • MariaDB (2)
      • MySQL (2)
      • Oracle (0)
      • MSSQL (1)
      • Cubrid (0)
    • PC (2)
      • 견적함 (2)
      • 정보 (0)

블로그 메뉴

    공지사항

    인기 글

    태그

    • 몬스터
    • 스타2
    • 숨겨진
    • c#
    • MySQL
    • 유디아
    • 모험의서
    • 디펜스
    • 로스트아크
    • docker
    • 뷰포인트
    • db
    • 서
    • 아르테미스
    • JavaScript
    • 모코코
    • html
    • 모험의
    • web
    • 히든
    • 씨앗
    • 구릉지
    • jQuery
    • 개인복권디펜스
    • 조합
    • Linux
    • 개복디
    • 오즈혼
    • css
    • 모험의 서

    최근 댓글

    최근 글

    티스토리

    hELLO · Designed By 정상우.
    Codit Develop

    Codit Develop

    Develop/PHP

    [PHP] DB -> JSON 형식 출력 (유니코드 변환)

    2018. 10. 27. 16:52
    반응형
    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'); 
    } 
     
    ?>
     
    Colored by Color Scripter
    cs
    반응형
    저작자표시 비영리 변경금지 (새창열림)

    'Develop > PHP' 카테고리의 다른 글

    [PHP] VSCode 디버그 활성화  (0) 2021.06.23
      'Develop/PHP' 카테고리의 다른 글
      • [PHP] VSCode 디버그 활성화
      Codit Develop
      Codit Develop
      내가 보려고 만든 개발 블로그

      티스토리툴바