PDO,准备使用

时间:2014-10-27 16:27:09

标签: php mysql pdo

if($_POST["type"] == "checkEmail")
         {
              $sql = "SELECT *  FROM `user` WHERE user_email=:email";
              $statement = $mysql->prepare($sql);

              $email = $mysql->quote($_POST["email"]);
              $statement->execute(Array(":email"=>$email));
              $re = $statement->fetchAll();
              if(1)
                 print_r(json_encode($re));//echo json_encode("Sorry,Some has tood that good e-mail:<");
              else
                 print_r(json_encode($re));
         }

我尝试使用查询功能,但它确实有效!但是准备功能不起作用!

1 个答案:

答案 0 :(得分:1)

不要使用 - &gt; quote(), - &gt; prepare()已经这样做了。

if($_POST["type"] == "checkEmail")
     {
          $sql = "SELECT *  FROM `user` WHERE user_email=:email";
          $statement = $mysql->prepare($sql);

          $email = $_POST["email"];
          $statement->execute(Array(":email"=>$email));
          $re = $statement->fetchAll();
          if(1)
             print_r(json_encode($re));//echo json_encode("Sorry,Some has tood that good e-mail:<");
          else
             print_r(json_encode($re));
     }

如果这不是问题,那么你应该发布你得到的错误:

if($statement->execute(Array(":email" => $email))) {
   // your code
} else {
   print_r(json_encode($statement->errorInfo());
}