그누보드 모든 게시판에 특정 필드를 일괄 추가하기 (2017-11-14 12:27 수정)
그누보드 게시판에 특정 필드를 한번에 추가할때 사용하기 위해 만들었습니다.
그누보드5 폴더에 table_filed_add.php 라는 파일을 생성후 브라우저로 실행하면 추가됩니다.
<?php
include_once "_common.php";
$dbconn = mysqli_connect(G5_MYSQL_HOST,G5_MYSQL_USER,G5_MYSQL_PASSWORD,G5_MYSQL_DB) ;
if (!$dbconn) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$sql = "select * from ".$g5['board_table']." order by bo_table asc ";
$result = mysqli_query($dbconn,$sql);
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
// 추가할 필드명
$hp_add_field = "";
// 추가할 필드명 속성
$hp_add_field_type = " varchar(255) NOT NULL DEFAULT '' ";
// 특정 필드 뒤에 추가하기
// $hp_add_field_after = " AFTER wr_10 ";
if (!$hp_add_field) {
echo '추가할 필드이름을 넣으세요';
exit;
}
$id_num = "0";
while($data = mysqli_fetch_array($result)) {
echo $data["bo_table"] ."<br>";
$field_query = "SHOW COLUMNS FROM ".$g5['write_prefix'] . $data["bo_table"]." WHERE Field = '".$hp_add_field."';";
$field_row = sql_fetch( $field_query );
if(!$field_row['Field']) {
sql_query(" ALTER TABLE ".$g5['write_prefix'] . $data["bo_table"]." ADD ".$hp_add_field . $hp_add_field_type . $hp_add_field_after." ", true);
}
}
echo mysqli_error($dbconn);
// close connection
mysqli_close($dbconn);
?>
참고자료
http://majesty76.tistory.com/27
https://stackoverflow.com/questions/17541312/alter-table-add-multiple-columns-after-column1
댓글 2개
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4399 | ||
| 2424 | 1년 전 | 1143 | ||
| 2423 | 1년 전 | 1161 | ||
| 2422 |
|
1년 전 | 1838 | |
| 2421 | 1년 전 | 1064 | ||
| 2420 |
|
1년 전 | 1845 | |
| 2419 | 1년 전 | 1153 | ||
| 2418 | 1년 전 | 1141 | ||
| 2417 | 1년 전 | 927 | ||
| 2416 | 1년 전 | 1226 | ||
| 2415 | 1년 전 | 1109 | ||
| 2414 | 1년 전 | 996 | ||
| 2413 | 1년 전 | 1400 | ||
| 2412 |
|
1년 전 | 2004 | |
| 2411 | 1년 전 | 994 | ||
| 2410 | 1년 전 | 1861 | ||
| 2409 | 1년 전 | 1694 | ||
| 2408 | 1년 전 | 1192 | ||
| 2407 | 1년 전 | 1159 | ||
| 2406 | 1년 전 | 833 | ||
| 2405 | 1년 전 | 2044 | ||
| 2404 |
와칸다포에버
|
1년 전 | 1049 | |
| 2403 | 1년 전 | 1125 | ||
| 2402 |
뽕엄능브라
|
1년 전 | 2054 | |
| 2401 | 1년 전 | 1161 | ||
| 2400 | 1년 전 | 1262 | ||
| 2399 | 1년 전 | 1849 | ||
| 2398 | 1년 전 | 1578 | ||
| 2397 | 1년 전 | 1895 | ||
| 2396 | 1년 전 | 1260 | ||
| 2395 | 1년 전 | 1081 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기