我试图从mysqli迁移到pdo,但遇到了一个问题。
$sql = "select concat(register.fname ,' ' ,register.lname) as name,register.matric as matric,register.username as uname,register.sex as sex,register.phone as phone ,register.passport as passport ,register.email as email,register.level as level,faculty.fac_name as fac,dept.dept_name as dept,diary.diary as diary,diary.date_added as added
from register,faculty,dept,diary
where register.user_id = :_id and diary.username = :name limit 1";
$sth = $dbh->prepare($sql);
$sth->bindValue(':id', $id, PDO::PARAM_INT);
$sth->bindParam(':name', $username);
$sth->execute();
显示此错误:
警告:PDO语句::bindValue()[pdostatement.bindvalue]:SQLSTATE[HY093]:无效的参数号:会话信息:SESSION_ID = mjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
3条答案
按热度按时间jum4pzuy1#
在查询中,您在绑定值
:id
中将其命名为:_id
。vjhs03f72#
您有
:_id
,请在bindValue
调用中更改它tuwxkamq3#
你将变量
$id
绑定到:id
,但在语句中你需要:_id
。或者更改声明: