【发布时间】:2015-10-15 18:14:59
【问题描述】:
我需要获取一个由类组成的多维数组,访问结果时出现错误 Parse error: syntax error, unexpected '$Contrato' (T_VARIABLE) in instruction
print_r $Contrato->getDatosContrato();
有什么想法吗? 这是我的代码
require_once('config.php');
class Contrato {
public $mainContractor;
public $MiCodigo;
public $title;
public $description;
public $buyerCompany;
public $buyerUser;
public $buyerUserId;
public $categoryCode;
public $categoryName;
public function getDatosContrato() {
$parametros = array(
"contract"=> array(
"mainContractor" => array(
"id" => $this->mainContractor
),
"MiCodigo" => $this->MiCodigo,
"title" => $this->title,
"description" => $this->description,
"buyerCompany" => array(
"id" => $this->buyerCompany
),
"buyerUser" => $this->buyerUser,
"buyerUserId" => $this->buyerUserId,
"categoryList" => array(
"category" => array(
"categoryCode" => $this->categoryCode,
"categoryName" => $this->categoryName
)
)
)
);
return $parametros;
}
}
try
{
$BD = new PDO("mysql:host=".DB_HOST.";dbname=".DB_DATABASE, DB_USER, DB_PASSWORD);
$stmt = $BD->query("SELECT * FROM Contracts");
$stmt->setFetchMode(PDO::FETCH_INTO, new Contrato);
foreach($stmt as $Contrato)
{
print_r $Contrato->getDatosContrato().'<br />';
}
$BD = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
【问题讨论】:
-
非常感谢大家,我看不出问题:))