为什么我准备好的陈述不能正常运作?

时间:2014-04-06 11:46:33

标签: php mysql pdo

我有一个附属于php处理程序的ajax调用,其中包含一个准备好的语句。

它不会起作用。没有发现错误。

当我将其从弃用的mysql_real_escape更改为pdo prepared statememt时,它才停止工作。

这是我的代码:

$create_pdo=new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$statement=$create_pdo->prepare("INSERT INTO REGISTRY (fname, lname, email, password, age, sex, city, timereg, frcode) VALUES (:fname_received, :lname_received, :email_received,  :password_received, :dob_received, :sex_received, :city_received, :timepassreg, :frcode)");
$statement->bindParam(':fname_received', $fname_received);
$statement->bindParam(':lname_received', $lname_received);
$statement->bindParam(':email_received', $email_received);
$statement->bindParam(':password_received', $password_received);
$statement->bindParam(':dob_received', $dob_received);
$statement->bindParam(':sex_received', $sex_received);
$statement->bindParam(':city_received', $city_received);
$statement->bindParam(':timepassreg', $timepassreg);
$statement->bindParam(':frcode', $frcode);
$statement_executed=$statement->execute();
if ($statement_executed){
$messagetosend="<font size=\"2\" color=\"#347C17\" face=\"Tahoma\"> <strong>Приветствуем нового пользователя проекта 'Фаворит'!</strong></font>,<br><font size=\"2\"        color=\"#1F2320\" face=\"Tahoma\">Для того, чтобы начать пользоваться нашим сайтом, вам нужно будет ввести авторизационный код.<br>Ваш авторизационный код: <font size=\"2\" color=\"#336699\" face=\"Tahoma\"><strong>".$frcode."</strong></font><br>Этот процесс проводится в целях борьбы со спамом и его предотвращения.<br>С уважением,<br>Проект 'Фаворит'.</font>";
$mailheader='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$mailheader.="X-Mailer: PHP \r\n";
$mailheader.="From: Фаворит <passwordreminder@favorit.kz>";
mail($email_received,"Авторизация на проекте 'Фаворит'",$messagetosend,$mailheader);
$array_to_json=array("database_input" => "true","mail_sent" => "true");
echo json_encode($array_to_json);
}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

  

它不会奏效。没有发现任何错误。

要显示查询错误,您需要将错误模式属性设置为PDO :: ATTR_ERRMODE。然后,您将能够以与其他PHP错误相同的方式查看PDO错误

$create_pdo=new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$create_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$statement=$create_pdo->prepare('INSERT INTO REGISTRY (fname, lname, email, password, age, sex, city, timereg, frcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)');
$statement_executed = $statement->execute(array($fname_received, $lname_received, $email_received, $password_received, $dob_received, $sex_received, $city_received, $timepassreg, $frcode));