묻고답하기
page_full_width">
게시판 글 엑셀로 가져오기 오류...
2017.03.20 17:30
안녕하세요?
아무래도 해결이 나지 않아 문의드립니다.
모든 값은 정상적으로 기입했는데요, mysql 명령어 오류가 자꾸 나길래 mysqli로 바꾸어서 실행해도 정상적인 동작을 하지 않습니다.
mariadb 10을 사용중인 것 같고요, 아래와 같이 변환해서 오류가 나는데 어떻게 처리해야할까요 ㅠㅠ
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | <?php //url 로 직접 불러오는것을 방지 //if(!strstr($_SERVER['HTTP_REFERER'],$_SERVER['SERVER_NAME'])&& !strstr($_SERVER['HTTP_REFERER'],'out_excel.php')) exit; $info = array ( "host" => "localhost" , "user" => "**" , "pass" => "**" , "db" => "**" , "table" => "xe_documents" , "module_srl" => "**" , ); $getFields = array ( "title" , "regdate" , "content" ); //출력원하는 칼럼을 배열로 입력 header( "Content-type: application/vnd.ms-excel" ); header( "Content-Disposition: attachment; filename=doc_" . date ( 'Ymd' ). ".xls" ); $con = mysqli_connect( $info [host], $info [user], $info [pass]) || die (mysqli_error()); $con_db = mysqli_select_db( $con , $info [db]) || die (mysqli_error()); mysqli_query( $con , "set names utf8" ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <head> <meta http-equiv=Content-Type content=text/html; charset= "utf-8" > </head> <body> <table border=1> <tr align=center> <?php //제목 불러오기 $fields = mysqli_list_fields( "$info[db]" , "$info[table]" ); $columns = mysqli_num_fields( $fields ); for ( $i =0 ; $i < $columns ; $i ++ ) { $field [ $i ]=mysqli_field_name( $fields , $i ); if ( in_array( $field [ $i ], $getFields ) ) echo "<th>" . $field [ $i ]. "</th>" ; } //확장변수의 타이틀은 값이므로 $result = mysqli_query( "select var_name from xe_document_extra_keys where module_srl = $info[module_srl]" ); while ( $data = mysqli_fetch_array( $result ) ) { echo "<th>" .htmlspecialchars( $data [var_name]). "</th>" ; } echo "</tr>" ; //데이터 불러오기 $result = mysqli_query( "select * from $info[table] where module_srl = $info[module_srl]" ); while ( $data = mysqli_fetch_assoc( $result ) ) { echo "<tr>" ; foreach ( $data as $key => $val ) { if ( in_array( $key , $getFields ) ) { if ( $key == 'regdate' ) { echo "<td style='mso-number-format:\"0_ \";' >" .htmlspecialchars( $val ). "</td>" ; } elseif ( $key == 'content' ){ //내용 출력할경우 태그가 그대로 출력됨 //echo "<td>".$val."</td>"; //셀이 두칸이상으로 늘어남 echo "<td >" .htmlspecialchars( strip_tags ( str_replace ( " " , "" , $val ))). "</td>" ; } else { echo "<td>" .htmlspecialchars( $val ). "</td>" ; } } if ( $key == 'document_srl' ){ //확장변수 불러올때 사용 $d_srl = $val ; } } //확장변수 출력 //////////////////////////////////////////// //eid리스트를 불러온다 $query =mysqli_query( "select eid from xe_document_extra_keys where module_srl = $info[module_srl]" ); while ( $extra_title =mysqli_fetch_array( $query )) { echo "<td>" ; $egetFields = array ( "value" , "eid" ); //확장변수 값을 불러와 eid값이 같은곳에 출력 $extra_result = mysqli_query( "select * from xe_document_extra_vars where document_srl = $d_srl" ); while ( $edata = mysqli_fetch_assoc( $extra_result ) ) { $extra_str = "" ; foreach ( $edata as $key => $val ){ if ( in_array( $key , $egetFields ) ){ $extra_str = $val . "," . $extra_str ; } } $extra_arr = explode ( "," , $extra_str ); if ( $extra_title [eid]== $extra_arr [0]){ //전화번호값은 "|@|" 를 "-" 로 변경 if ( $extra_title [eid]== "mb_phone_Number" ){ echo str_replace ( "|@|" , "-" ,htmlspecialchars( $extra_arr [1])); //기타 배열값들은 ',' 로 변경 } elseif ( $extra_title [eid]== "mb_incomplete" || $extra_title [eid]== "mb_cs" ){ echo str_replace ( "|@|" , "," ,htmlspecialchars( $extra_arr [1])); } else { echo htmlspecialchars( $extra_arr [1]); } } } echo "</td>" ; //eid값이 없으면 빈칸입력 } ///////////////////////////////////////////////////////////////////// echo "</tr>" ; } ?> </table> </body> </html> |
mysqli 는 기존 mysql 부분 값들을 mysqli 로 바꾼다고 해결되지 않아요 ^^;;
받는 파라메타(변수) 값의 순서가 달라요...
mysql 과 mysqli 비교해둔 거 구글링해보면 많을거예요
보시면서 mysqli 함수 사용한 부분을 다 고치셔야할거예요