私は確実にオブジェクトを持っているので、私は自分のエラーを理解していません. 以下の私のprint_rを見てください:
注意: 21 行目で C:\xampp\htdocs\travel_mvc\cockpit\index.php の非オブジェクトのプロパティを取得しようとしています
そして21行目と持っています:
echo $row->tz_name.'<br>';
私のprint_r:
Array
(
[0] => stdClass Object
(
[tz_name] => Africa/Abidjan
)
[1] => stdClass Object
(
[tz_name] => Africa/Accra
)
[2] => stdClass Object
(
[tz_name] => Africa/Addis_Ababa
)
[3] => stdClass Object
(
[tz_name] => Africa/Algiers
)
[4] => stdClass Object
(
[tz_name] => Africa/Asmara
)
)
私のクラスでは:
class model{
private $fields = '*';
private $table = '';
private $where = '';
private $and = '';
private $limit = '';
private $order = '';
private $type_order = 'DESC';
private $d = array();
public function find($data = array()){
if(isset($data['fields'])){
$this->fields = $data['fields'];
}
$this->table = $data['table'];
if(isset($data['where'])){
$this->where = ' WHERE '.$data['where'];
}
if(isset($data['and'])){
$this->and = ' WHERE '.$data['and'];
}
if(isset($data['limit'])){
$this->limit = ' LIMIT '.$data['limit'];
}
if(isset($data['order'])){
$this->order = ' ORDER BY '.$data['order'].$type_order;
}
$query = Db::getInstance()->prepare('SELECT '.$this->fields.'
FROM '.$this->table.$this->where.
$this->and.$this->order.$this->limit.'');
$query->execute();
while($data = $query->fetchAll(PDO::FETCH_OBJ)){
$d[] = $data;
}
return($d);
}
}
そして、関数を呼び出すと:
$model = new model();
$sql = $model->find(array(
'fields'=>'tz_name',
'table'=>'times_zones',
'limit'=>5
));
foreach($sql as $row):
echo $row->tz_name.'<br>';
endforeach;
echo '<pre>';
print_r($row);
echo '</pre>';