Sorry, I posted this in the coding section, however, it didn't show up... No idea what's up with that, but it probably belongs here anyways.
I'm trying to create a new object that will allow for basic mysql functions to be more easily used in children of this class. I'm not sure though how the children would access a spefic object and not just the general class.
Here's a simple example of what I'm trying:
class mysqlObject {
var $last_query;
var $db_host;
function mysqlObject($username, $password, $host, $db) {
$this->$db_host = mysql_connect($host, $username, $password);
if (!$this->$db_host) return false;
mysql_select_db($db);
}
}
class mysqlTable extends mysqlObject {
var $last_query;
var $dbtable;
function mysqlTable($table) {
$this->$dbtable = $table;
return $this->$dbtable;
}
function select_all() {
$this->$last_query = "SELECT * FROM $this->dbtable";
return $this->$last_query;
}
}
class phpBasic extends mysqlTable {
var $db_table;
function php_basic() {
return true;
}
function get_total() {
$result = mysqlTable::run_query(select_all());
$number = MYSQL_NUMROWS($result);
return $number;
}
}
$mysql = new mysqlObject('user', 'pass', 'host.com', 'db');
if (!$mysql) $failure = "Cannot connect to database<br>";
$dbtable = new mysqlTable('table');
if (!$dbtable) $failure = "No table of this name<br>";
$basic = new phpBasic();
if (!$basic) $failure = "Something bad happened<br>";
I know this definately will not work but I can't really explain why...
If anyone could just lead me in the right direction at the absolute least, it would be greatly helpful. Please let me know. 🙂 Thanks!