Php 在他们的ORM中这样做,类似于@ethrbunny所建议的。但是,当从数据库中运行选择时,这会起作用吗?我想我的问题还不够清楚。我真的希望运行一个查询,其中可能包括连接(出于性能原因)。然后,在查询完成后,我不确定处理数据的最佳方式是什么-作为数组还是作为
Php 在他们的ORM中这样做,类似于@ethrbunny所建议的。但是,当从数据库中运行选择时,这会起作用吗?我想我的问题还不够清楚。我真的希望运行一个查询,其中可能包括连接(出于性能原因)。然后,在查询完成后,我不确定处理数据的最佳方式是什么-作为数组还是作为,php,mysql,Php,Mysql,在他们的ORM中这样做,类似于@ethrbunny所建议的。但是,当从数据库中运行选择时,这会起作用吗?我想我的问题还不够清楚。我真的希望运行一个查询,其中可能包括连接(出于性能原因)。然后,在查询完成后,我不确定处理数据的最佳方式是什么-作为数组还是作为对象。@Jonathan,然后您必须创建组合模型类,然后逐步进行处理。 foreach ($members as $member) { echo $member->full_name(); echo $member->
在他们的ORM中这样做,类似于@ethrbunny所建议的。但是,当从数据库中运行
选择时,这会起作用吗?我想我的问题还不够清楚。我真的希望运行一个查询,其中可能包括连接(出于性能原因)。然后,在查询完成后,我不确定处理数据的最佳方式是什么-作为数组还是作为对象。@Jonathan,然后您必须创建组合模型类,然后逐步进行处理。
foreach ($members as $member)
{
echo $member->full_name();
echo $member->age();
}
SELECT IFNULL(SUM(table2.big_name),0) AS sumBig
...
$result=$PDO->fetchObject();
$sum=$result->sumBig;
$conn = DBConnection::_getSubjectsDB();
$query = "select * from studies where Status = 1";
$st = $conn->prepare( $query );
$st->execute();
$rows = $st->fetchAll();
foreach ( $rows as $row )
{
$study = (object)array();
$study->StudyId = $row[ 'StudyId' ];
$study->Name = $row[ 'StudyName' ];
$study->Investigator = $row[ 'Investigator' ];
$study->StartDate = $row[ 'StartDate' ];
$study->EndDate = $row[ 'EndDate' ];
$study->IRB = $row[ 'IRB' ];
array_push( $ret, $study );
}
/** Single location info
*/
class Location
{
/** Name
* @var string
*/
public $Name;
/** Address
* @var string
*/
public $Address;
/** City
* @var string
*/
public $City;
/** State
* @var string
*/
public $State;
/** Zip
* @var string
*/
public $Zip;
/** getMailing
* Get a 'mailing label' style output
*/
function getMailing()
{
return $Name . "\n" . $Address . "\n" . $City . "," . $State . " " . $Zip;
}
}
$conn = DBConnection::_getLocationsDB();
$query = "select * from Locations where Status = 1";
$st = $conn->prepare( $query );
$st->execute();
$rows = $st->fetchAll();
foreach ( $rows as $row )
{
$location = new Location();
$location->Name= $row[ 'Name' ];
$location->Address = $row[ 'Address ' ];
$location->City = $row[ 'City' ];
$location->State = $row[ 'State ' ];
$location->Zip = $row[ 'Zip ' ];
array_push( $ret, $location );
}
foreach( $ret as $location )
{
echo $location->getMailing();
}
stdClass Object
(
[id] => 1
[title] => Article Title
[published] => 2013-03-04 16:30:00
[category] => stdClass Object
(
[id] => 1
[name] => Category Name
)
)
<?php echo $article->category->name; ?>
<?php echo $article->getCategory()->getName(); ?>
class Member_Details {
public $id;
public $first_name;
public $last_name;
public function FullName() {
return $this -> first_name." ".$this -> last_name;
}
}
class Member_Address {
public $id;
public $address;
public $city;
}
class MemberJoins {
public $objects = array();
}
$obj_details = new Member_Details();
$obj_address = new Member_Address();
//Add data to the objects and then
//Then create the join object
$obj_address_details = new MemberJoins();
$obj_address_details -> objects = array($obj_details, $obj_address);