note 113796 added to language.oop5.interfaces
| From: | laxmanraovl at gmail dot com | Date: | Tue, 03 Dec 2013 13:20:31 +0000 |
| Subject: | note 113796 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197731@lists.php.net to get a copy of this message | ||
Here is a sample database interfaces which you can optimize some areas....
interface databaseconstants
{
const DB_HOST = 'HOSTNAME';
const DB_USER = 'USERNAME';
const DB_PASSWORD = 'PASSWORD';
const DB_NAME = 'DATABASE';
}
Interface databasefunctions
{
public function dbQuery($sql);
public function dbAffectedRows();
public function dbFetchArray($result, $resultType = MYSQL_NUM);
public function dbFetchAssoc($result);
public function dbFetchRow($result);
public function dbFetchObject();
public function dbFreeResult($result);
public function dbNumRows();
public function dbSelect();
public function dbInsertId();
}
class database implements dbconstants, dbfunctions
{
private static $instance;
protected $query_id='';
// Constructor
public function __construct()
{
//self::$instance =& $this;
$this->link = $this->dbconnect();
$this->db=$this->dbSelect();
}
// Interface Functions
public function dbconnect()
{
return mysql_connect(dbconstants::DB_HOST,dbconstants::DB_USER,dbconstants::DB_PASSWORD);
}
public function dbSelect()
{
return mysql_select_db(dbconstants::DB_NAME,$this->link);
}
public function dbQuery($sql)
{
return $this->query_id = mysql_query($sql) or die (mysql_error().'<p><b>SQL
Query Error :</b><br>'.$sql.'</p>');
}
public function dbAffectedRows()
{
return mysql_affected_rows();
}
public function dbFetchArray($result,$resultType = MYSQL_NUM)
{
return mysql_fetch_array($result, $resultType);
}
public function dbFetchAssoc($result)
{
return mysql_fetch_assoc($result);
}
public function dbFetchRow($result)
{
return mysql_fetch_row($result);
}
public function dbFetchObject()
{
return mysql_fetch_object($this->query_id);
}
public function dbFreeResult($result)
{
return mysql_free_result($result);
}
public function dbNumRows()
{
return mysql_num_rows($this->query_id) or die(mysql_error().'<p><b>SQL Error
:</b><br>'.$this->query_id.'</p>');
}
public function dbInsertId()
{
return mysql_insert_id();
}
}
class category extends database
{
public function __construct()
{
parent::__construct();
}
public function getCategory($catId)
{
$DtSql=$this->dbQuery("SELECT name FROM category WHERE id='{$catId}' limit
1");
if($this->dbNumRows())
{
$RsRow=$this->dbFetchObject();
return $RsRow->name;
}
else
{
return '';
}
}
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 117.237.132.189
----
Manual Page -- http://php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/113796
Del: integrated -- https://master.php.net/note/delete/113796/integrated
Del: useless -- https://master.php.net/note/delete/113796/useless
Del: bad code -- https://master.php.net/note/delete/113796/bad+code
Del: spam -- https://master.php.net/note/delete/113796/spam
Del: non-english -- https://master.php.net/note/delete/113796/non-english
Del: in docs -- https://master.php.net/note/delete/113796/in+docs
Del: other reasons-- https://master.php.net/note/delete/113796
Reject -- https://master.php.net/note/reject/113796
Search -- https://master.php.net/manage/user-notes.php