php 회원가입 db 질문 드립니다.
미해결
Fatal error : Uncaught Error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in C:\Apache24\htdocs\dbcon.php:8 Stack trace: #0 C:\Apache24\htdocs\index.php(2): include() #1 {main} thrown in C:\Apache24\htdocs\dbcon.php on line 8 . APM 환경에서 php로 회원가입을 구현하고 싶은데 위와 같은 오류가 뜹니다. 오류 문장에 언급된 php 파일 첨부합니다.. 찾아봐도 잘 안 나오고 뭐가 문제인지 모르겠습니다. ㅇ위에서 말한 line 8은 아래입니다. 오래 붙잡았는데도 도저히 모르겠습니다.. 도와주시면 감사하겠습니다. $options = array ( PDO ::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ); dbcon.php <?php $host = 'localhost' ; $username = '' ; $password = '' ; $dbname = 'userdb' ; $options = array ( PDO ::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ); try { $con = new PDO ( "mysql:host={ $host };dbname={ $dbname };charset=utf8" , $username , $password ); } catch ( PDOException $e ) { die ( "Failed to connect to the database: " . $e -> getMessage ()); } $con -> setAttribute ( PDO ::ATTR_ERRMODE, PDO ::ERRMODE_EXCEPTION); $con -> setAttribute ( PDO ::ATTR_DEFAULT_FETCH_MODE, PDO ::FETCH_ASSOC); if ( function_exists ( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc ()) { function undo_magic_quotes_gpc ( & $array ) { foreach ( $array as & $value ) { if ( is_array ( $value )) { undo_magic_quotes_gpc ( $value ); } else { $value = stripslashes ( $value ); } } } undo_magic_quotes_gpc ( $_POST ); undo_magic_quotes_gpc ( $_GET ); undo_magic_quotes_gpc ( $_COOKIE ); } header ( 'Content-Type: text/html; charset=utf-8' ); session_start (); ? > index.php <?php include ( 'dbcon.php' ); include ( 'check.php' ); if ( is_login ()){ if ( $_SESSION [ 'user_id' ] == 'admin' && $_SESSION [ 'is_admin' ]== 1 ) header ( "Location: admin.php" ); else header ( "Location: welcome.php" ); } ? > <! DOCTYPE html > < html > < head > < title > 로그인 예제 </ title > < link rel = "stylesheet" href = "bootstrap/css/bootstrap1.min.css" > </ head > < body > < div class = "container" > < h2 align = "center" > 로그인 </ h2 >< hr > < form class = "form-horizontal" method = "POST" > < div class = "form-group" style = " padding: 10px 10px 10px 10px; " > < label for = "user_name" > 아이디: </ label > < input type = "text" name = "user_name" class = "form-control" id = "inputID" placeholder = "아이디를 입력하세요." required autocomplete = "off" readonly onfocus = " this . removeAttribute ('readonly'); " /> </ div > < div class = "form-group" style = " padding: 10px 10px 10px 10px; " > < label for = "user_password" > 패스워드: </ label > < input type = "password" name = "user_password" class = "form-control" id = "inputPassword" placeholder = "패스워드를 입력하세요." required autocomplete = "off" readonly onfocus = " this . removeAttribute ('readonly'); " /> </ div > < div class = "checkbox" > < label >< input type = "checkbox" > 아이디 기억 </ label > </ div > </ br > < div class = "from-group" style = " padding: 10px 10px 10px 10px; " > < button type = "submit" name = "login" class = "btn btn-success" > 로그인 </ button > < a class = "btn btn-success" href = "registration.php" style = " margin-left: 50px " > < span class = "glyphicon glyphicon-user" ></ span > 등록 </ a > </ div > </ br > </ form > </ div > </ body > </ html > <?php $login_ok = false ; if ( ( $_SERVER [ 'REQUEST_METHOD' ] == 'POST' ) and isset ( $_POST [ 'login' ]) ) { $username = $_POST [ 'user_name' ]; $userpassowrd = $_POST [ 'user_password' ]; if ( empty ( $username )){ $errMSG = "아이디를 입력하세요." ; } else if ( empty ( $userpassowrd )){ $errMSG = "패스워드를 입력하세요." ; } else { try { $stmt = $con -> prepare ( 'select * from users where username=:username' ); $stmt -> bindParam ( ':username' , $username ); $stmt -> execute (); } catch ( PDOException $e ) { die ( "Database error. " . $e -> getMessage ()); } $row = $stmt -> fetch (); $salt = $row [ 'salt' ]; $password = $row [ 'password' ]; $decrypted_password = decrypt ( base64_decode ( $password ), $salt ); if ( $userpassowrd == $decrypted_password ) { $login_ok = true ; } } if ( isset ( $errMSG )) echo "<script>alert(' $errMSG ')</script>" ; if ( $login_ok ){ if ( $row [ 'activate' ]== 0 ) echo "<script>alert(' $username 계정 활성이 안되었습니다. 관리자에게 문의하세요.')</script>" ; else { session_regenerate_id (); $_SESSION [ 'user_id' ] = $username ; $_SESSION [ 'is_admin' ] = $row [ 'is_admin' ]; if ( $username == 'admin' && $row [ 'is_admin' ]== 1 ) header ( 'location:admin.php' ); else header ( 'location:welcome.php' ); session_write_close (); } } else { echo "<script>alert(' $username 인증 오류')</script>" ; } } ? >
- apache
- mysql
- db
- php
- 서버





