db_host;dbname=$this->db_na-6ren">
gpt4 book ai didi

php - PDO::bindValue 未定义

转载 作者:行者123 更新时间:2023-11-29 04:19:26 26 4
gpt4 key购买 nike

我对 php 中的 bind* 函数有疑问

我的代码是:

$this->db_conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name", $this->db_user, $this->db_pass);
$this->db_conn -> query ('SET NAMES utf8');
$this->db_conn -> query ('SET CHARACTER_SET utf8_unicode_ci');
$this->db_conn -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db_conn -> prepare('INSERT INTO `users` (`login`, `password`, `mail`) VALUES(:login,sha1(:password),:mail)');
$this->db_conn -> bindValue(':login', $login, PDO::PARAM_STR);
$this->db_conn -> bindValue(':password', $password, PDO::PARAM_STR);
$this->db_conn -> bindValue(':mail', $mail, PDO::PARAM_STR);
$this->db_conn -> execute();

错误是:

Fatal error: Call to undefined method PDO::bindParam()

有人可以给我建议吗?

最佳答案

bindParam()bindValue()PDOStatement 的方法,由 prepare() 返回方法。您需要存储对 prepare() 的调用的返回值,并在其上调用 bindParam()bindValue()

试试这个:

$this->db_conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name", $this->db_user, $this->db_pass);
$this->db_conn -> query ('SET NAMES utf8');
$this->db_conn -> query ('SET CHARACTER_SET utf8_unicode_ci');
$this->db_conn -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $this->db_conn -> prepare('INSERT INTO `users` (`login`, `password`, `mail`) VALUES(:login,sha1(:password),:mail)');
$stmt -> bindValue(':login', $login, PDO::PARAM_STR);
$stmt -> bindValue(':password', $password, PDO::PARAM_STR);
$stmt -> bindValue(':mail', $mail, PDO::PARAM_STR);
$stmt -> execute();

关于php - PDO::bindValue 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29759624/

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