简体   繁体   中英

Using PDO Query reset my server

I've some trouble with my website. It works perfectly on localhost, but since yesterday I tried to put it on my windows 2003 server. (with apache 2.2.11, mysql 5.1.31, php 5.2.8).

My problem is when I try to use authentification page of my website, server reset.

It reset only if I call the PDO->query function (to get user on my database)

My query code :

function getUser($login)
{
    try{
        $bdd = connectDB();

        $requete = $bdd->query('SELECT * FROM `utilisateur` WHERE `Login` = \''.$login.'\'');

        $user = new Utilisateur();

        if($donnees = $requete->fetch())
        {
            $user->setLogin($donnees['Login']);
            $user->setAuth($donnees['Role']);
            $user->setTrigramme($donnees['Trigramme']);
        }

        $requete->closeCursor();

        disconnectDB($bdd);
        return $user;
    }catch(Exception $e){
        error_log('Exception : 
                '.$e, 3, ADR_ERROR_LOG);
    }
}

Line : ConnectDb works fine, but when it arrive on the net line, navigator (I've tried with IE, Chrome and Firefox) wait a long time and said 'Connexion with the server has been reset', and I've none error message on my error log:(

Thank's in advance

EDIT : I've tried like this, and still have the same problem :

function getUser($login)
{
    try{
        $bdd = connectDB();

        $requete = $bdd->prepare('SELECT * FROM `utilisateur` WHERE `Login` = :login');

// $requete = $bdd->query('SELECT * FROM utilisateur WHERE Login = \\''.$login.'\\'');

        $requete->bindValue('login', $login, PDO::PARAM_STR);
        $requete->execute();

        $user = new Utilisateur();

        if($donnees = $requete->fetch())
        {
            $user->setLogin($donnees['Login']);
            $user->setAuth($donnees['Role']);
            $user->setTrigramme($donnees['Trigramme']);
        }

        $requete->closeCursor();

        disconnectDB($bdd);
        return $user;
    }catch(Exception $e){
        error_log('Exception : 
                '.$e, 3, ADR_ERROR_LOG);
    }
}

EDIT 2 This works with this : BUT WHY ???

$db = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    mysql_select_db(DB_NAME,$db);

    $sql = 'SELECT * FROM `utilisateur` WHERE `Login` = \''.$login.'\'';

    $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

    $user = new Utilisateur();

    while($donnees = mysql_fetch_assoc($req))
    {
        $user->setLogin($donnees['Login']);
        $user->setAuth($donnees['Role']);
        $user->setTrigramme($donnees['Trigramme']);
    }

    mysql_close();
    return $user;

Finally I use mysqli_ to do what I wanted and it works perfectly.

If someone have a solution about this problem, He could put it in order to help the next person.

Thank's to the persons who have search solution.

I think you have just got a typo in your code. With PDO a typo can determine your fate and have you scratching your head for a minute. Look at your prepare query. When you bind the login parameter you never specified the : before login.

Look at this part:

$requete->bindValue('login', $login, PDO::PARAM_STR);

So "login" should be ":login". Just for future reference you don't have to use PDO::PARAM_STR because any parameters bound to the query are automatically handled as strings. If you were binding a numeric value then you'd want to set the data type to PDO::PARAM_INT.

PDO can be tricky - especially when it comes to typos and errors.

Long story short I think the parameter naming issue is all of your problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM