PHP & Others

mysql의 grant문을 이용한 초간단 사용자계정 만들기

컨텐츠 정보

본문


----------------파일명 : grant0.php-------------
<center>데이터베이스 권한부여 테스트</center><br><br>

<form method = "post" action = "grant.php">
아이디 <input type = "text" name = "user_name"><br>
비밀번호 <input type = "password" name = "user_pw"><br>
데이터베이스 <input type="text" name="data"><br>
<input type = "submit" name = "botten" value = "전송"><br>
</form><br>
새로 만들 아이디와 비밀번호를 적어주세요.
--------------------------------------------------
--------------파일명 : grant.php--------------------
<?
$mysql_host = "";                        // 호스트
$mysql_user = "";                        // root 유저
$mysql_pw = "";                        // root 유저의 비밀번호
$mysql_db = "";                        // mysql 데이터베이스 변수

if($user_name == $mysql_user){
?>
<script>
window.alert('root 이름은 사용할 수 없습니다.');
history.go(-1);
</script>
<?
}

$connect = mysql_connect($mysql_host, $mysql_user, $mysql_pw);
mysql_select_db($mysql_db);

$query1 = "grant all privileges on $data.* to $user_name@\\"$mysql_host\\" identified by '$user_pw'";
if(mysql_query($query1)) echo "<script>window.alert('권한부여를 무사히 마쳤습니다.');history.go(-1);</script>";

mysql_close();
?>
-----------------------------------------------------------
grant.php파일 위에 있는 변수설정부분을 각자의 root계정으로 설정하기만 하면 됩니다.

관련자료

댓글 0
등록된 댓글이 없습니다.
Today's proverb
행복해지고 싶다면, 잠시 동안만이라도 가슴에 손을 얹고 생각해 보라. 그러면 진정한 즐거움은, 발치에 돋아나는 잡초나 아침 햇살에 빛나는 꽃의 이술과 같이 우리 주변에 무수히 널려 있다는 것을 알 수 있을 것이다. 《하루 5분 생각이 인생을 결정한다 》 (이범준)