请尝试从mysqli移动到pdo但运行此代码
<?php
$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();
?>
它显示此错误(!)警告:PDOStatement :: bindValue()[pdostatement.bindvalue]:SQLSTATE [HY093]:参数号无效:参数未在C:\ wamp \ www \ uni \ det \ viewuser中定义第14行的.php
答案 0 :(得分:1)
在查询中,您已将其命名为绑定值:_id
中的:id
。
答案 1 :(得分:0)
您有:_id
,请在bindValue
电话
答案 2 :(得分:0)
您将变量$id
绑定到:id
,但在声明中需要:_id
。
$sth->bindValue(':_id', $id, PDO::PARAM_INT);
或者更改声明:
$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";