Hi,
Any tips on how I can make a smarter function? I have recently begun oop, so Im not allways sure if I do things in a "bad way" - both the amount of code, and the performance.
Any advice on this piece is appreciated:
class get_page_info
{
public $id;
public $h_id;
public $titel;
public $link;
public $url;
public $publiceret;
public $indhold;
public $meta_desc;
public $meta_key;
public $oprettet;
public $oprettet_af;
public $opdateret;
public $opdateret_af;
public $indekseret;
public $beskyttet;
public $layout;
public function __construct( $id )
{
// Database object :
$database = new PDO_CONNECTION(DSN, USER, PASS);
// Prepare query :
$stmt = $database->prepare("SELECT id, h_id, titel, link, url, publiceret, indhold, meta_desc, meta_key, oprettet,
oprettet_af, opdateret, opdateret_af, indekseret, beskyttet, layout
FROM pages
WHERE SHA1(id) = :id");
// Execute :
$stmt->execute( array( ':id' => $id ) );
// Fetch :
while( $data = $stmt->fetch( PDO::FETCH_ASSOC ))
{
$this->id = $data['id'];
$this->h_id = $data['h_id'];
$this->titel = $data['titel'];
$this->link = $data['link'];
$this->url = $data['url'];
$this->publiceret = $data['publiceret'];
$this->indhold = $data['indhold'];
$this->meta_desc = $data['meta_desc'];
$this->meta_key = $data['meta_key'];
$this->oprettet = $data['oprettet'];
$this->oprettet_af = $data['oprettet_af'];
$this->opdateret = $data['opdateret'];
$this->opdateret_af = $data['opdateret_af'];
$this->indekseret = $data['indekseret'];
$this->beskyttet = $data['beskyttet'];
$this->layout = $data['layout'];
}
}
}
How can I simply use $stmt->fetchAll() - How do i get the data outside the class, if i do that? Would be nice to spare all the properties and the while loop...