0

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;
Nanis
  • 361
  • 6
  • 18
  • 1
    I hope you're santizing that $login variable. Why aren't you using PDO binding for query parameters to make things more safe? – Alex Jan 30 '14 at 09:00
  • I've no soucy with parameters, otherwise this wouldn't works on localhost no ? I've search lot of thinks about this problem, and I find people who has the same problem, some answer say that we must close connection. On my disconnectDB() function I do it so I don't know ... Anyway it crash on the requete line, and I don't find anythink about this. – Nanis Jan 30 '14 at 09:24
  • If I do this, I've no trouble and if I do the same select on phpmyadmin,no problem: [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('somelogin'); $user->setAuth(3); $user->setTrigramme('APE'); // } // $requete->closeCursor(); disconnectDB($bdd); return $user; }catch(Exception $e){ error_log('Exception : '.$e, 3, ADR_ERROR_LOG); } }[/code] – Nanis Jan 30 '14 at 09:28
  • I've edited my post. Why do it work without PDO ??? – Nanis Jan 30 '14 at 10:14
  • I suppose that "server reset" actually means "500 Internal Server Error" status code and/or a blank page. That means that your script is throwing an error but you haven't configured PHP to display error messages. You can hopefully find the error messages in the Apache log. Otherwise, here's a [brief explanation to reconfigure PHP](http://stackoverflow.com/a/5680885/13508). The error reporting thumb rule is: show in development, log in production. – Álvaro González Jan 30 '14 at 10:30
  • Does you connect script return the PDO object? We kind of need to see what is in that code – Alex Jan 30 '14 at 10:37
  • function connectDB(){ try{ $bdd = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.'', ''.DB_USER.'', ''.DB_PASSWORD.''); $bdd->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); return $bdd; }catch(Exception $e){ error_log(' Error connectDB() : '.$e->getMessage().' ', 3, ADR_ERROR_LOG); } } No problem, $bdd is a PDO Object – Nanis Jan 30 '14 at 10:43
  • SIMPLE DEBUG.if($donnees = $requete->fetch()) { echo "OK"; }else{ echo "NOT OK" } – david strachan Jan 30 '14 at 10:54
  • This works... if I comment the pdo->query – Nanis Jan 30 '14 at 11:15

2 Answers2

0

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.

Nanis
  • 361
  • 6
  • 18
0

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.

Tyler
  • 69
  • 8
  • what do you means with : "before login" ? In my code, I get login on my Form, and past it to this function. Login is never null or =''; I check it before calling function – Nanis Jan 30 '14 at 14:33