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계정으로 설정하기만 하면 됩니다.

관련자료

등록된 댓글이 없습니다.
Today's proverb
사랑이 손을 내밀면 비켜서거나 물러서지 마라. 사랑을 하기도 전에 사랑의 비극적인 종말을 예감해 외면한다는 것은 바보짓이다. (이정하)