Page 911 - 3-2
P. 911

라 데이터베이스의 값을 가져오는.              PHP  소스


            <?php
            // array for JSON response
                $response = array();


             //  데이터베이스 접속 문자열. (db         위치 유저 이름 비밀번호,  ,       )
                $connect=mysqli_connect("localhost", "root", "", "and1") or
                    die( "SQL server 에 연결할 수 없습니다.");




                //mysqli_query("SET NAMES UTF8");
               //  데이터베이스 선택
               //mysqli_select_db($connect,"and1") or die('DB  선택 실패');


               //  세션 시작
               //session_start();


               //  쿼리문 생성
               $sql = "select * from project";


               //  쿼리 실행 결과를 $result     에 저장
               $result = mysqli_query($connect, $sql);
               //  반환된 전체 레코드 수 저장.
               $total_record = mysqli_num_rows($result);


                // check for empty result
                if (mysqli_num_rows($result) > 0) {
                // looping through all results


                // products node
                // success
                $response["status"] = "OK";
                $response["num_results"] = $total_record;
                $response["results"] = array();


                while ($row = mysqli_fetch_array($result)) {
                    // temp user array
                    $results = array();
                    $results["detector"] = $row["detector"];
                    $results["addr"] = $row["addr"];
                    $results["room"] = $row["room"];
                    $results["fire"] = $row["fire"];
                    $results["spark"] = $row["spark"];
                    $results["gas"] = $row["gas"];


                                                         - 911 -
   906   907   908   909   910   911   912   913   914   915   916