简体   繁体   English

使用PDO Query重置服务器

[英]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. 它可以在localhost上完美运行,但是从昨天开始,我试图将其放在Windows 2003服务器上。 (with apache 2.2.11, mysql 5.1.31, php 5.2.8). (使用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) 仅当我调用PDO-> query函数时才会重置(以使用户访问我的数据库)

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:( 线路:ConnectDb可以正常工作,但是当它到达网络线路时,导航器(我已经尝试过IE,Chrome和Firefox)等待了很长时间,并说“与服务器的Connexion已被重置”,而且我没有任何错误错误日志上的消息:(

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 = $ 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 ??? 编辑2与此作品:但为什么?

$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. 最后,我使用mysqli_来做我想做的事,并且效果很好。

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. 使用PDO,错字可以决定您的命运,让您挠头一分钟。 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". 因此,“登录”应为“: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. 只是为了将来参考,您不必使用PDO :: PARAM_STR,因为绑定到查询的任何参数都会自动处理为字符串。 If you were binding a numeric value then you'd want to set the data type to PDO::PARAM_INT. 如果要绑定数字值,则需要将数据类型设置为PDO :: PARAM_INT。

PDO can be tricky - especially when it comes to typos and errors. PDO可能很棘手-特别是在输入错误和错误时。

Long story short I think the parameter naming issue is all of your problems. 长话短说,我认为参数命名问题是您所有的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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