2014-12-04 4 views
0

나는 데이터베이스에 연결하려고 시도했지만 불행히도 전혀하지 않습니다. 맨 아래에 스크립트가 있습니다. 먼저 스크립트를 가리켜 서 이상한 점이 있는지 궁금해합니다.PHP를 통해 데이터베이스에 연결

필자가 조사한 바에 따르면 필자가 작성한 php 방법은 작고 똑같은 작년을 사용했다는 것을 알았습니다.

연결되지 않는다는 것을 분명히하는 것은 무엇이든지 알려줍니다.

감사합니다.

connect.php :

<?php 
$connect_error = 'Sorry, we\'re experiencing connection problems.'; 
mysql_connect('localhost', 'devdegre_ddevlin', 'password123') or die($connect_error); 
mysql_select_db('devdegre_logreg') or die($connect_error); 
?> 

init.php : I는 사용자 데이터베이스를 생성하는 SQL을 덤프하고 사용자가 입력 한

<?php 
session_start(); 
//error_reporting(0); 

require 'database/connect.php'; 
require 'functions/general.php'; 
require 'functions/users.php'; 

$current_file = explode('/', $_SERVER['SCRIPT_NAME']); 
$current_file = end($current_file); 

if (logged_in() === true) { 
$session_user_id = $_SESSION['user_id']; 
$user_data = user_data($session_user_id, 'user_id', 'username', 'password', 
     'first_name', 'last_name', 'email', 'password_recover', 'type', 

'allow_email', 'profile'); 
if (user_active($user_data['username']) === false) { 
    session_destroy(); 
    header('Location: index.php'); 
    exit(); 
} 
if ($current_file !== 'changepassword.php' && $user_data['password_recover'] == 1) { 
    header('Location: changepassword.php?force'); 
    exit(); 
} 
} 

$errors = array(); 
?> 

. 항상 connect.php로 이동하여 사용자 이름, 암호 등을 연결하는 다양한 방법을 시도해 보았습니다.

+0

mysql.it가 사용되지 않습니다. – Nick

+0

당신이'user_data()'함수를 보여주지 않았기 때문에 우리는 당신을 도울 수 없습니다. –

+0

당신은 아마 google 'OOP 프로그래밍'도해야합니다 ... – RichardBernards

답변

0

mysql 및 그 밖의 구성 요소는 보안 문제와 성능으로 인해 가치가 하락하므로 여기 mysqli 클래스 사용 :

<?php 
    /* database connection information */ 
    $server = ""; 
    $user = ""; 
    $password = ""; 
    $database = ""; 

    /* query */ 
    $query = " 
     SELECT id 
     FROM whatever 
    "; 

    /* error messages */ 
    $messErr_connectionDatabaseFailed = "Error : connection failed. Please try later."; 

    $link = new mysqli($server, $user, $password, $database); 

    /* If connection failed */ 
    if (!$link) { 
     printf($messErr_connectionDatabaseFailed); 
     printf("<br />"); 
    } 
    /* If connection successed */ 
    else { 
     $resultQuery = $link->query($query); 

     /* find around mysqli::fetch_assoc() function to display result */ 
    } 
?> 

쿼리 부분은 선택 사항입니다.

+0

그래, 문제가 해결되었습니다. 고마워요! – Dev

관련 문제