Im Having Some Wired OOP Problems Im New To PHP OOP So i need Some Help Ive Created Three Classes 1) class.mysql.php 2) class.error.php 3) class.template.php
But When I create An Instance Of Mysql Class On My Index Page The First Method Works (Connect) But When I Activate The Next Method Which Is Select The DB (select_db) it throws Me An Error :
Fatal error: Call to undefined method mysql::select_db() in E:\root****\htdocs\portal\index.php on line 9
While The Method Exist!!
Heres The Source Code Of them
1 class.mysql.php
<?php
/*
##################################
#File Name : class.mysql.php #
#Description : Mysql Wrapper #
#Started On : FRI 21/10/2005 #
#Last Edited : FRI 21/10/2005 #
#By : Ahmed Kamil #
##################################
*/
class mysql{
function check_error($errmsg){
if (!empty($errmsg)){
$handle = new error;
$handle->showerror($errmsg);
exit;
}
}
function connect($host , $username , $password){
$connect = @mysql_connect($host , $username , $password) or $errmsg = mysql_error();
$this->check_error($errmsg);
}
}
// Select The DB
function select_db($db){
$selectdb = @mysql_select_db($db) or $errmsg = mysql_error();
$this->check_error($errmsg);
}
// Execute Select Query
function query($coloum , $table , $tbl2, $like ){
$query = "SELECT $coloum FROM $table WHERE $tbl2='$like'";
$exe = @mysql_query($query) or $errmsg = mysql_error();
$this->check_error($errmsg);
}
?>
And Here Comes The Code Fo class.error.php
<?php
/*
##################################
#File Name : class.mysql.php #
#Description : Error Management #
#Started On : FRI 21/10/2005 #
#Last Edited : FRI 21/10/2005 #
#By : Ahmed Kamil #
##################################
*/
class error{
function showerror($errmsg){
echo '<table width="489" height="94" border="0" align="center">';
echo ' <tr>';
echo ' <td width="483" height="44" valign="top"><span class="style1">An Error Has Occured You May Have Done Something Wrong Thats Why Your Information Is Logged <br />';
echo ' The Error Returned Was:</span></td>';
echo ' </tr>';
echo ' <tr>';
echo ' <td valign="top"><textarea name="textarea" cols="62" rows="10">'.$errmsg.'</textarea></td>';
echo ' </tr>';
echo '</table>';
}
}
?>
And Here Come The Sourc Of the Index Page
require "classes/class.error.php";
require "classes/class.mysql.php";
require "classes/class.template.php";
require "settings.php";
$sql = new mysql;
$tpl = new TemplatePowerParser("templates/main/index.tpl" , T_BYVAR);
$sql->connect($main['db']['host'] , $main['db']['username'] , $main['db']['password']);
// here It Throws Me An error While The Method Exists!!!!
$sql->select_db($main["db"]["databse"]);