我得到這個錯誤,我跑:缺少參數爲__construct
$db = new PDO('mysql:host=localhost;dbname=MYDATABASE', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$Manager = new CompanyManager($db);
$Manager->getList();
錯誤:
Warning: Missing argument 2 for Company::__construct(), called in /.../CompanyManager.class.php on line 53 and defined in /.../Company.class.php on line 17
這裏是CompanyManager.class.php部分:
public function getList()
{
$Company = array();
$q = $this->_db->query('SELECT id, statut, company, activity, source, secteur, comments, offer_date, entry_date, type_ope, gestionnaire, next_step FROM prospect ORDER BY id');
while ($donnees = $q->fetch(PDO::FETCH_ASSOC))
{
$Company[] = new Company($donnees);
}
return $Company;
}
這裏是Company.class.php(有趣的部分):
<?php
class Company
{
private $_id;
private $_statut;
private $_company;
private $_activity;
private $_source;
private $_secteur;
private $_comments;
private $_offerDate;
private $_entryDate;
private $_typeOpe;
private $_gestionnaire;
private $_nextStep;
public function __construct($id, $statut, $company, $activity, $source, $secteur, $comments, $offerDate, $entryDate, $typeOpe, $gestionnaire, $nextStep)
{
$this->setId($id);
$this->setStatut($statut);
$this->setCompany($company);
$this->setActivity($activity);
$this->setSource($source);
$this->setSecteur($secteur);
$this->setComments($comments);
$this->setOfferDate($offerDate);
$this->setEntryDate($entryDate);
$this->setTypeOpe($typeOpe);
$this->setGestionnaire($gestionnaire);
$this->setNextStep($nextStep);
}
非常感謝大家誰要去嘗試給我一隻手;-)
這是不行的,在哪裏'$ id','$ statut等來自你的while循環?我認爲他們需要''donnees ['id']'etc – martynthewolf
@martynthewolf我舉一個例子,其中錯誤 – som
while($ donnees = $ q-> fetch(PDO :: FETCH_ASSOC)) { $公司[] =新公司($ id,$ statut,$ company,$ activity,$ source,.....); } 這是不正確的。 – martynthewolf