그누보드 모든 게시판에 특정 필드를 일괄 추가하기 (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년 전 | 4400 | ||
| 2394 | 1년 전 | 5049 | ||
| 2393 |
|
1년 전 | 1699 | |
| 2392 |
|
1년 전 | 1358 | |
| 2391 |
|
1년 전 | 1140 | |
| 2390 |
|
1년 전 | 1192 | |
| 2389 | 1년 전 | 1780 | ||
| 2388 | 1년 전 | 1324 | ||
| 2387 | 1년 전 | 1308 | ||
| 2386 |
투명한열정
|
1년 전 | 3073 | |
| 2385 |
|
1년 전 | 2341 | |
| 2384 | 1년 전 | 1666 | ||
| 2383 | 1년 전 | 1802 | ||
| 2382 | 1년 전 | 1455 | ||
| 2381 |
|
1년 전 | 1872 | |
| 2380 | 1년 전 | 1042 | ||
| 2379 | 1년 전 | 1385 | ||
| 2378 | 1년 전 | 919 | ||
| 2377 | 1년 전 | 2997 | ||
| 2376 | 1년 전 | 1562 | ||
| 2375 | 1년 전 | 1735 | ||
| 2374 |
네이비스택
|
1년 전 | 1114 | |
| 2373 | 1년 전 | 1547 | ||
| 2372 | 1년 전 | 1468 | ||
| 2371 |
goodman148
|
1년 전 | 2111 | |
| 2370 | 1년 전 | 1518 | ||
| 2369 |
|
1년 전 | 1031 | |
| 2368 | 1년 전 | 1836 | ||
| 2367 | 1년 전 | 1356 | ||
| 2366 |
|
1년 전 | 1212 | |
| 2365 | 1년 전 | 2141 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기