Found This Simple Usage for Mysql With Object Oriented Style......From Facebook
<?php
/**
* mysqllib.php
* A Simple Usage of Mysql with
* Object Oriented Style
* Written Just For Manage The
* Functions Easly And Make the Funny
* The Connection :)
* */
/******************************
* Main Structure Of Library.. *
*******************************/
class MysqlLib
{
/**
* $Link : For Connection to Server
* with mysql_connect() function
* @access Public
* */
Public $Link;
/**
* $Dblink : Connection to Database
* with mysql_select_db() function
* @access Public
* */
Public $DbLink;
/**
* $SqlLink : For mysql_query() unction
* @access Public
* */
Public $SqlLink;
/**
* $NumRow: Getting Num Rows of Last Result
* or Last Query
* @access Public
* */
Public $NumRow;
/**
* $Error : for mysql_error()
* @access Public
* */
Public $Error;
/**
* $ErrNo : get the error code of last query
* @access Public
* */
Public $ErrNo;
/**
* $Assocative : for get mysql_fetch_assoc() function
* @access Public
* */
Public $Assocative;
/**
* Constructionof Class
* $host : mysql server name
* $user : mysql access username
* $pass : mysql access password
* $db : your database
* */
function __construct($host,$user,$pass,$db)
{
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->dbnm = $db;
}
/**
* Gets the Host name By the __construct function
* @access Public
* @return Bool
* */
Public Function getHost()
{
return $this->host;
}
/**
* Gets the username By the __construct function
* @access Public
* @return String
* */
Public Function getUser()
{
return $this->user;
}
/**
* Gets the password By the __construct function
* @access Public
* @return String
* */
Public Function getPass()
{
return $this->pass;
}
/**
* Gets the Database By the __construct function
* @access Public
* @return String
* */
Public Function getDb()
{
return $this->dbnm;
}
/**
* Make connection For Server And Database
* @access Public
* @return Bool
* */
Public Function init()
{
$this->Link = mysql_connect($this->getHost(),$this->getUser(),$this->getPass()) or die(mysql_error());
$this->DbLink = mysql_select_db($this->getDb(),$this->Link) or die(mysql_error());
}
/**
* Sends the Sql Query to Server
* @access Public
* @return Bool
* */
Public Function initSql($sql)
{
$this->SqlLink = mysql_query($sql) or die(mysql_error());
return $this->SqlLink;
}
/**
* Gets Affected Num Rows By the Last Query
* @access Public
* @return Int
* */
Public Function getNumRow()
{
$this->NumRow = mysql_num_rows($this->SqlLink) or die(mysql_error());
return $this->NumRow;
}
/**
* Gets All Given Data to assocative Array
* @access Public
* @return String
* */
Public Function FetchAssoc()
{
$this->Assocative = mysql_fetch_assoc($this->SqlLink) or die(mysql_error());
return $this->Assocative;
}
/**
* Gets The Last error
* @access Public
* @return String
* */
Public Function getError()
{
$this->Error = mysql_error();
return $this->Error;
}
/**
* Gets the Error Code of Last operation
* @access Public
* @return Int
* */
Public Function getErrorNo()
{
$this->ErrNo = mysql_errno();
return $this->ErrNo;
}
}
?>
<?php
/**
* mysqllib.php
* A Simple Usage of Mysql with
* Object Oriented Style
* Written Just For Manage The
* Functions Easly And Make the Funny
* The Connection :)
* */
/******************************
* Main Structure Of Library.. *
*******************************/
class MysqlLib
{
/**
* $Link : For Connection to Server
* with mysql_connect() function
* @access Public
* */
Public $Link;
/**
* $Dblink : Connection to Database
* with mysql_select_db() function
* @access Public
* */
Public $DbLink;
/**
* $SqlLink : For mysql_query() unction
* @access Public
* */
Public $SqlLink;
/**
* $NumRow: Getting Num Rows of Last Result
* or Last Query
* @access Public
* */
Public $NumRow;
/**
* $Error : for mysql_error()
* @access Public
* */
Public $Error;
/**
* $ErrNo : get the error code of last query
* @access Public
* */
Public $ErrNo;
/**
* $Assocative : for get mysql_fetch_assoc() function
* @access Public
* */
Public $Assocative;
/**
* Constructionof Class
* $host : mysql server name
* $user : mysql access username
* $pass : mysql access password
* $db : your database
* */
function __construct($host,$user,$pass,$db)
{
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->dbnm = $db;
}
/**
* Gets the Host name By the __construct function
* @access Public
* @return Bool
* */
Public Function getHost()
{
return $this->host;
}
/**
* Gets the username By the __construct function
* @access Public
* @return String
* */
Public Function getUser()
{
return $this->user;
}
/**
* Gets the password By the __construct function
* @access Public
* @return String
* */
Public Function getPass()
{
return $this->pass;
}
/**
* Gets the Database By the __construct function
* @access Public
* @return String
* */
Public Function getDb()
{
return $this->dbnm;
}
/**
* Make connection For Server And Database
* @access Public
* @return Bool
* */
Public Function init()
{
$this->Link = mysql_connect($this->getHost(),$this->getUser(),$this->getPass()) or die(mysql_error());
$this->DbLink = mysql_select_db($this->getDb(),$this->Link) or die(mysql_error());
}
/**
* Sends the Sql Query to Server
* @access Public
* @return Bool
* */
Public Function initSql($sql)
{
$this->SqlLink = mysql_query($sql) or die(mysql_error());
return $this->SqlLink;
}
/**
* Gets Affected Num Rows By the Last Query
* @access Public
* @return Int
* */
Public Function getNumRow()
{
$this->NumRow = mysql_num_rows($this->SqlLink) or die(mysql_error());
return $this->NumRow;
}
/**
* Gets All Given Data to assocative Array
* @access Public
* @return String
* */
Public Function FetchAssoc()
{
$this->Assocative = mysql_fetch_assoc($this->SqlLink) or die(mysql_error());
return $this->Assocative;
}
/**
* Gets The Last error
* @access Public
* @return String
* */
Public Function getError()
{
$this->Error = mysql_error();
return $this->Error;
}
/**
* Gets the Error Code of Last operation
* @access Public
* @return Int
* */
Public Function getErrorNo()
{
$this->ErrNo = mysql_errno();
return $this->ErrNo;
}
}
?>
0 Comments:
Post a Comment