我一直在谷歌上搜索这个错误,但我无法解决。
我在user.php文件中有我的用户类:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class User
{
private $usr_id;
private $utp_id;
private $usr_login;
private $usr_password;
private $usr_firstname;
private $usr_lastname;
private $usr_active;
private $usr_created_usrid;
private $usr_created_date;
private $usr_modified_userid;
private $usr_modified_date;
function __construct($usr_id, $utp_id, $usr_login, $usr_password, $usr_firstname, $usr_lastname,
$usr_active, $usr_created_usrid, $usr_created_date, $usr_modified_userid, $usr_modified_date)
{
$this->usr_id = $usr_id;
$this->utp_id = $utp_id;
$this->usr_login = $usr_login;
$this->usr_password = $usr_password;
$this->usr_firstname = $usr_firstname;
$this->usr_lastname = $usr_lastname;
$this->usr_active = $usr_active;
$this->usr_created_usrid = $usr_created_usrid;
$this->usr_created_date = $usr_created_date;
$this->usr_modified_userid = $usr_modified_userid;
$this->usr_modified_date = $usr_modified_date;
}
// some code to generate getters and setters
?>
我还有另一个使用pdo登录的文件,userDAO.php:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once '../db/accessDB.php';
require_once '../class/user.php';
class UserDAO
{
public function loginUser($usr_login, $usr_password)
{
try {
$pdo = AccessDB::getConnectionPDO();
$pwd_md5 = md5($usr_password);
$user = new User('', '', $usr_login, $pwd_md5);
$sql = 'SELECT '
. ' a.utp_id, a.usr_firstname, a.usr_lastname,'
. ' b.utp_type'
. ' FROM lm_user a, lm_usertype b'
. ' WHERE'
. ' a.utp_id=b.utp_id AND'
. ' a.usr_login="?" AND a.usr_password="?" AND '
. ' a.usr_active="1" ';
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $user->getUsr_login(), PDO::PARAM_STR);
$stmt->bindParam(2, $user->getUsr_password(), PDO::PARAM_STR);
echo $sql;
} catch (Exception $ex) {
throw $ex;
}
}
}
?>
问题是,当我想测试它时,我有以下错误:
可能是什么问题?问候。
答案 0 :(得分:1)
$user = new User('', '', $usr_login, $pwd_md5);
,它与User类构造函数参数__construct($usr_id, $utp_id, $usr_login, $usr_password, $usr_firstname, $usr_lastname, $usr_active, $usr_created_usrid, $usr_created_date, $usr_modified_userid, $usr_modified_date)
不匹配。由于所有参数都不是选项,因此您需要在创建对象时强制传递所有参数。