gpt4 book ai didi

php - 真正准备好时会默默失败,模仿时会有效

转载 作者:行者123 更新时间:2023-11-29 22:30:09 25 4
gpt4 key购买 nike

出于安全目的,我将 ATTR_EMULATE_PREPARES 选项设置为 false。在开发环境中,ATTR_ERRMODE 为 ERRMODE_EXCEPTION。

但是这段代码:

// $this->bdd is juste a regular PDO instance with some options
$req = $this->bdd->prepare('INSERT INTO users VALUES(NULL, :login, :passwd, :email, :firstname, :lastname, :role, :token_id, :confirmed, :registration_date, :last_connexion_date)');

$req->bindValue(':login', $login, PDO::PARAM_STR);
$req->bindValue(':passwd', $passwd, PDO::PARAM_STR);
$req->bindValue(':email', $email, PDO::PARAM_STR);
$req->bindValue(':firstname', $firstname, PDO::PARAM_STR);
$req->bindValue(':lastname', $lastname, PDO::PARAM_STR);
$req->bindValue(':role', $role, PDO::PARAM_INT);
$req->bindValue(':token_id', $token_id, PDO::PARAM_INT);
$req->bindValue(':confirmed', $confirmed, PDO::PARAM_BOOL);
$req->bindValue(':registration_date', $registration_date, PDO::PARAM_STR);
$req->bindValue(':last_connexion_date', $last_connexion_date, PDO::PARAM_STR);

return $req->execute() ? true : $req->errorInfo();

只是默默地失败,错误代码为 00000。在浏览 stackoverflow 和其他平台时,我发现了一些与“真正准备好的声明”相关的类似错误,这些错误可以解决(对我来说不起作用)。我决定打开仿真,效果非常好。

我的问题:我想保留真正准备好的陈述,但我不知道出了什么问题......

编辑:我只是出于测试目的从 PDO 更改为 MySQLi,MySQLi 可以工作,PDO 不能(并且仍然失败)这里的脚本:

http://pastebin.com/jvjsfFVC

MySQLi 总是执行真正准备好的语句

最佳答案

在代码之间使用 try catch,这样如果遇到错误,我们可以看到错误数组而不是空白。

 try {
$req = $this->bdd->prepare('INSERT INTO users VALUES(NULL, :login, :passwd, :email, :firstname, :lastname, :role, :token_id, :confirmed, :registration_date, :last_connexion_date)');

$req->bindValue(':login', $login, PDO::PARAM_STR);
$req->bindValue(':passwd', $passwd, PDO::PARAM_STR);
$req->bindValue(':email', $email, PDO::PARAM_STR);
$req->bindValue(':firstname', $firstname, PDO::PARAM_STR);
$req->bindValue(':lastname', $lastname, PDO::PARAM_STR);
$req->bindValue(':role', $role, PDO::PARAM_INT);
$req->bindValue(':token_id', $token_id, PDO::PARAM_INT);
$req->bindValue(':confirmed', $confirmed, PDO::PARAM_BOOL);
$req->bindValue(':registration_date', $registration_date, PDO::PARAM_STR);
$req->bindValue(':last_connexion_date', $last_connexion_date, PDO::PARAM_STR);
$execute = $req->execute();
} catch (PDOException $error) {
print_r($error);
die();


}

关于php - 真正准备好时会默默失败,模仿时会有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29878131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com