PHP classes Best Practise
Posted: Wed Aug 22, 2012 2:06 am
Hi guys!
I've been designing quite low-usage websites, but now I've given task to design website service with potentially higher usage. I'm not so familiar with Object-Oriented PHP programming, so I'd like to ask simple best practice -question. It's more theoretical question.
I have written some PHP class libraries for my use. For example, I have one for login management, one for MySQL handling etc. etc. Now I have used this kind of approach, and I'm wondering if it's totally wrong when it comes to performance or security.
Example scenario:
Any comments, links, book titles that could help me, are more than welcome!
I've been designing quite low-usage websites, but now I've given task to design website service with potentially higher usage. I'm not so familiar with Object-Oriented PHP programming, so I'd like to ask simple best practice -question. It's more theoretical question.
I have written some PHP class libraries for my use. For example, I have one for login management, one for MySQL handling etc. etc. Now I have used this kind of approach, and I'm wondering if it's totally wrong when it comes to performance or security.
Example scenario:
Code: Select all
class MySQL {
public function __construct(...) {
...
}
function connect() {
...
}
function select_db() {
...
}
function query($qry) {
...
}
}
Code: Select all
class other {
public function __construct(...,$dbconn) {
$this->mysql = $dbconn;
}
function do_some_magic() {
$this->mysql->query("TRUNCATE DATABASE xxx");
...
}
}
Code: Select all
<?php
require_once 'inc/class.user.php';
require_once 'inc/class.other.php';
$mysql = new MySQL(...);
$mysql->connect();
$mysql->select_db();
$other = new other($mysql);
$other->do_some_magic();