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
인생을 목적으로서가 아니라 하나의 과정으로서 계속되는 여행이라고 생각하라. 당신의 인생 여행은 매일매일 가능한 한 인간적으로 즐길 수 있는 것이다. 꽃향기를 맡기 위해 시간을 내라. 매일매일의 생활이 가끔 어떠한 어려운 문제에 봉착하든지 간에 그 일정 부분을 즐겨라. (제럴드 쿠셀 "성공의 비밀" 中에서)