2

请尝试从 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]: Invalid parameter number: parameter was not defined in C:\wamp\www\uni\det\viewuser.php on第 14 行

4

3 回答 3

1

在查询中,您已将其命名为:_idbind value :id

于 2012-10-10T18:42:55.387 回答
0

你有,在你的电话:_id中改变它bindValue

于 2012-10-10T18:43:05.550 回答
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";
于 2012-10-10T18:43:08.163 回答