php Util Classes
Php connection util Classes Code
code: save file UtilClass.php
<?php
class UtilClass {
public $utilMySqlServerIP;
public $utilDB ;
public $utilUser;
public $utilPass;
public $utilLink,$utilIsMYSQLLinked,$utilIsDBConnected;
public static $utilTitle,$utilDescription,$utilKeywords,$utilAuthor;
public $utilAns;
public function __construct() {
$this->utilMySqlServerIP = "localhost";
$this->utilUser = "root";//"root";
$this->utilPass = "";//"";
$this->utilDB = "photo-gallery";
$this->utilAns=false;
}
/////////////////// Start SEO Functions ///////////////////////////////////////////////
public static function getTitle() {
self::$utilTitle="Photo Gallety";
return (self::$utilTitle);
}
public static function getDescription(){
self::$utilDescription="Description";
return (self::$utilDescription);
}
public static function getKeywords(){
self::$utilKeywords="Keywords";
return (self::$utilKeywords);
}
public static function getAuthor(){
self::$utilAuthor="Author";
return (self::$utilAuthor);
}
public function getCreatedByName() {
return "CreatedByName";
}
public function getCreatedByWebAddress() {
return "CreatedByWebAddress";
}
public function getWebName() {
return "WebName";
}
public function getWebURL() {
return "WebURL";
}
/////////////////// End SEO Functions ///////////////////////////////////////////////
/////////////////// Start Host Functions ///////////////////////////////////////////////
public function getHost() {
return $this->utilMySqlServerIP;
}
public function getDb() {
return $this->utilDB;
}
public function getUser() {
return $this->utilUser;
}
public function getPass() {
return $this->utilPass;
}
///////////// Start Date and Time Functins////////////////
public function todayDDMMMYY($dt,$format='d-M-Y') {
date_default_timezone_set('Asia/Calcutta');
return date($format,strtotime($dt));
}
public function todayMMDDYY( $format = 'm-d-Y h:i:s A' ) {
date_default_timezone_set('Asia/Calcutta');
return date($format);
}
public function todayYYYYMMDD( $format = 'Y-m-d h:i:s A' ) {
date_default_timezone_set('Asia/Calcutta');
return date($format);
}
public function toDayDate( $format = 'm/d/Y' ) {
date_default_timezone_set('Asia/Calcutta');
return date($format);
}
public function toDayYear( $format = 'Y' ) {
return date($format);
}
////////////////// Start quoteToDbl Function //////////////////
public function quoteToDbl(&$input) {
$input=str_replace("'","''",$input);
$input=trim($input);
}
public function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
////////////////// End quoteToDbl Function //////////////////
////////////////// Start openCon Function //////////////////
public function openCon() {
$utilAns=false;
try {
$this->utilLink = mysql_connect($this->utilMySqlServerIP, $this->utilUser, $this->utilPass);
if (!is_resource($this->utilLink) || !$this->utilLink) {
$utilAns=false;
$utilIsMYSQLLinked=false;
}
else {
$utilIsMYSQLLinked=true;
if(mysql_select_db($this->utilDB,$this->utilLink)) {
$utilIsDBConnected=true;
$utilAns=true;
} else {
$utilIsDBConnected=false;
$utilAns=false;
}
}
}
catch(Exception $ee){
$utilIsDBConnected=false;
$utilIsMYSQLLinked=false;
$utilAns=false;
}
return $utilAns;
}
////////////////// End openCon Function //////////////////
////////////////// Start sendEMail Function //////////////////
public function sendEMail($tto, $fFrom, $sSubject, $bBody) {
/*if($tto=="") {
$tto="to@to.com";
}
if($fFrom=="") {
$fFrom="from@from.com";
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$tto . "\r\n";
$headers .= 'From: '.$fFrom . "\r\n";
mail($tto, $sSubject, $bBody, $headers);*/
$html_message = $bBody;
$mail = new PHPMailer();
$mail->From = $fFrom;
$mail->FromName = "Test".' '."Mail"; //name
$mail->Subject = $sSubject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($html_message);
$mail->AddAddress($tto);
$mail->Username = 'noreply@firstmedicalservices.com';
$mail->Password = 'noreply';
$mailAns = $mail->Send();
return $mailAns;
}
////////////////// End sendEMail Function //////////////////
////////////////// Start autoGeneratePass Function //////////////////
public function autoGeneratePass() {
$newpass="";
for($i=1;$i<=2;$i++){
$newpass=$newpass.chr(rand(65, 90));//A-Z
$newpass=$newpass.chr(rand(48, 57));//0-9
//$newpass=$newpass.chr(rand(97, 122));//a-z
}
return $newpass;
}
////////////////// End autoGeneratePass Function //////////////////
////////////////// Start makeMD5 Function //////////////////
public function makeMD5($st) {
$md=md5($st);
return $md;
}
public function counters($fileName) {
$count = file_get_contents($fileName);//create txt file and give 0 values in .txt file
$count = trim($count);
$count = $count + 1;
$fl = fopen($fileName,"w+");
fwrite($fl,$count);
fclose($fl);
}
////////////////// End makeMD5 Function //////////////////
////////////////// Start exportToExcelUtil Function //////////////////
public function exportToExcelUtil($filename,$data) {
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
}
////////////////// End exportToExcelUtil Function //////////////////
////////////////// Start secureSql Function //////////////////
public function secureSql($val) {
$val = str_ireplace("script", "blocked", $val);
$val = mysql_escape_string($val);
$this->quoteToDbl($val);
return $val;
}
////////////////// End secureSql Function //////////////////
////////////////// Start getRandomFileName Function //////////////////
public function getRandomFileName() {
$rndFileName=$this->makeMD5($this->today());
return $rndFileName;
}
////////////////// End getRandomFileName Function //////////////////
////////////////// Start getScript Name/ get Current Page Name Function //////////////////
function getScript() {
$file = $_SERVER["SCRIPT_NAME"];
$break = explode('/', $file);
$pfile = $break[count($break) - 1];
return $pfile;
}
////////////////// End getScript Name/ get Current Page Name Function //////////////////
////////////////// Start exeQuery Function //////////////////
public function exeQuery($qry) {
echo $qry;
try {
$res = mysql_query($qry, $this->utilLink);
if(!is_resource($res) || (!$res)) {
$res=false;
} else {
$numRows = mysql_num_rows($res);
if($numRows<=0) {
$res=false;
}
}
return $res;
}
catch(Exception $ee){
return (false);
}
}
////////////////// End exeQuery Function //////////////////
////////////////// Start closeCon Function //////////////////
public function closeCon() {
mysql_close($this->utilLink);
}
////////////////// End closeCon Function //////////////////
#----------------------------Start Utility Function ------------------#
public function __destruct() {
if($this->utilAns==true) {
$this->closeCon();}
}
}
?>
code: save file UtilClass.php
<?php
include_once("UtilClass.php");
class classes1 extends UtilClass {
var $host;
var $db ;
var $user;
var $pass;
var $link,$isDBConnect;
var $isError,$errorValue;
var $dt;
var $adminEmail,$adminMobile,$adminEmailPass,$adminEmailPort,$adminEmailHost,$scrollText;
function __construct() {
parent::__construct();
$this->host = parent::getHost();
$this->db = parent::getDb();
$this->user = parent::getUser();
$this->pass = parent::getPass();
try {
$this->link = mysql_connect($this->host, $this->user, $this->pass);
if (!is_resource($this->link)) {
$this->isDBConnect=false;
}
else {
$this->isDBConnect=true;
}
mysql_select_db($this->db,$this->link);
$this->getAdminAllInfo();
}
catch(Exception $ee){
$this->link=false;
}
}
public function setCon() {
$this->host = parent::getHost();
$this->db = parent::getDb();
$this->user = parent::getUser();
$this->pass = parent::getPass();
try {
$this->link = mysql_connect($this->host, $this->user, $this->pass);
if (!is_resource($this->link)) {
$this->isDBConnect=FALSE;
}
else {
$this->isDBConnect=TRUE;
}
mysql_select_db($this->db,$this->link);
}
catch(Exception $ee){
$this->link=FALSE;
}
}
public function getTotalRecord($table) {
$res=false;
$sSql="SELECT COUNT(*) AS total FROM $table";
try {
$rs=$this->exeQuery($sSql);
if($rs) {
$fQury=mysql_fetch_array($rs);
return $fQury['total'];
}
else { return 0; }
} catch(Exception $ee){
$res=false;
}
return $res;
}
public function activeDeactive($ID,$isActive,$tb, $colName) {
$ans="No";
$sSql="Update $tb set isActive=$isActive where $colName=$ID";
try {
$rs=$this->exeQuery($sSql);
if($rs) {
$ans="Yes";
} else { $ans="No"; }
} catch(Exception $ee){
$ans="No";
}
echo $ans;
}
public function deleteRecord($ID,$tb,$colName) {
$ans="No";
$sSql="delete from $tb where $colName=$ID";
try {
$rs=$this->exeQuery($sSql);
if($rs) {
$ans="Yes";
//unlink("../images/$dr/$ID.jpg");
} else { $ans="No"; }
} catch(Exception $ee){
$ans="No";
}
echo $ans;
}
///////////////////////////////////////////////////////////////////////////////////////////
public function exeQuery($query) {
$res=false;
try {
$res = mysql_query($query, $this->link);
}
catch(Exception $ee){
$res=false;
}
return $res;
}
public function getRow($res) {
$arr = @mysql_fetch_array($res, MYSQL_BOTH);
return $arr;
}
public function close() {
}
public function __destruct() {
mysql_close($this->link);
}
}
?>
code: save file UtilClass.php
<?php
class UtilClass {
public $utilMySqlServerIP;
public $utilDB ;
public $utilUser;
public $utilPass;
public $utilLink,$utilIsMYSQLLinked,$utilIsDBConnected;
public static $utilTitle,$utilDescription,$utilKeywords,$utilAuthor;
public $utilAns;
public function __construct() {
$this->utilMySqlServerIP = "localhost";
$this->utilUser = "root";//"root";
$this->utilPass = "";//"";
$this->utilDB = "photo-gallery";
$this->utilAns=false;
}
/////////////////// Start SEO Functions ///////////////////////////////////////////////
public static function getTitle() {
self::$utilTitle="Photo Gallety";
return (self::$utilTitle);
}
public static function getDescription(){
self::$utilDescription="Description";
return (self::$utilDescription);
}
public static function getKeywords(){
self::$utilKeywords="Keywords";
return (self::$utilKeywords);
}
public static function getAuthor(){
self::$utilAuthor="Author";
return (self::$utilAuthor);
}
public function getCreatedByName() {
return "CreatedByName";
}
public function getCreatedByWebAddress() {
return "CreatedByWebAddress";
}
public function getWebName() {
return "WebName";
}
public function getWebURL() {
return "WebURL";
}
/////////////////// End SEO Functions ///////////////////////////////////////////////
/////////////////// Start Host Functions ///////////////////////////////////////////////
public function getHost() {
return $this->utilMySqlServerIP;
}
public function getDb() {
return $this->utilDB;
}
public function getUser() {
return $this->utilUser;
}
public function getPass() {
return $this->utilPass;
}
///////////// Start Date and Time Functins////////////////
public function todayDDMMMYY($dt,$format='d-M-Y') {
date_default_timezone_set('Asia/Calcutta');
return date($format,strtotime($dt));
}
public function todayMMDDYY( $format = 'm-d-Y h:i:s A' ) {
date_default_timezone_set('Asia/Calcutta');
return date($format);
}
public function todayYYYYMMDD( $format = 'Y-m-d h:i:s A' ) {
date_default_timezone_set('Asia/Calcutta');
return date($format);
}
public function toDayDate( $format = 'm/d/Y' ) {
date_default_timezone_set('Asia/Calcutta');
return date($format);
}
public function toDayYear( $format = 'Y' ) {
return date($format);
}
////////////////// Start quoteToDbl Function //////////////////
public function quoteToDbl(&$input) {
$input=str_replace("'","''",$input);
$input=trim($input);
}
public function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
////////////////// End quoteToDbl Function //////////////////
////////////////// Start openCon Function //////////////////
public function openCon() {
$utilAns=false;
try {
$this->utilLink = mysql_connect($this->utilMySqlServerIP, $this->utilUser, $this->utilPass);
if (!is_resource($this->utilLink) || !$this->utilLink) {
$utilAns=false;
$utilIsMYSQLLinked=false;
}
else {
$utilIsMYSQLLinked=true;
if(mysql_select_db($this->utilDB,$this->utilLink)) {
$utilIsDBConnected=true;
$utilAns=true;
} else {
$utilIsDBConnected=false;
$utilAns=false;
}
}
}
catch(Exception $ee){
$utilIsDBConnected=false;
$utilIsMYSQLLinked=false;
$utilAns=false;
}
return $utilAns;
}
////////////////// End openCon Function //////////////////
////////////////// Start sendEMail Function //////////////////
public function sendEMail($tto, $fFrom, $sSubject, $bBody) {
/*if($tto=="") {
$tto="to@to.com";
}
if($fFrom=="") {
$fFrom="from@from.com";
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$tto . "\r\n";
$headers .= 'From: '.$fFrom . "\r\n";
mail($tto, $sSubject, $bBody, $headers);*/
$html_message = $bBody;
$mail = new PHPMailer();
$mail->From = $fFrom;
$mail->FromName = "Test".' '."Mail"; //name
$mail->Subject = $sSubject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($html_message);
$mail->AddAddress($tto);
$mail->Username = 'noreply@firstmedicalservices.com';
$mail->Password = 'noreply';
$mailAns = $mail->Send();
return $mailAns;
}
////////////////// End sendEMail Function //////////////////
////////////////// Start autoGeneratePass Function //////////////////
public function autoGeneratePass() {
$newpass="";
for($i=1;$i<=2;$i++){
$newpass=$newpass.chr(rand(65, 90));//A-Z
$newpass=$newpass.chr(rand(48, 57));//0-9
//$newpass=$newpass.chr(rand(97, 122));//a-z
}
return $newpass;
}
////////////////// End autoGeneratePass Function //////////////////
////////////////// Start makeMD5 Function //////////////////
public function makeMD5($st) {
$md=md5($st);
return $md;
}
public function counters($fileName) {
$count = file_get_contents($fileName);//create txt file and give 0 values in .txt file
$count = trim($count);
$count = $count + 1;
$fl = fopen($fileName,"w+");
fwrite($fl,$count);
fclose($fl);
}
////////////////// End makeMD5 Function //////////////////
////////////////// Start exportToExcelUtil Function //////////////////
public function exportToExcelUtil($filename,$data) {
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
}
////////////////// End exportToExcelUtil Function //////////////////
////////////////// Start secureSql Function //////////////////
public function secureSql($val) {
$val = str_ireplace("script", "blocked", $val);
$val = mysql_escape_string($val);
$this->quoteToDbl($val);
return $val;
}
////////////////// End secureSql Function //////////////////
////////////////// Start getRandomFileName Function //////////////////
public function getRandomFileName() {
$rndFileName=$this->makeMD5($this->today());
return $rndFileName;
}
////////////////// End getRandomFileName Function //////////////////
////////////////// Start getScript Name/ get Current Page Name Function //////////////////
function getScript() {
$file = $_SERVER["SCRIPT_NAME"];
$break = explode('/', $file);
$pfile = $break[count($break) - 1];
return $pfile;
}
////////////////// End getScript Name/ get Current Page Name Function //////////////////
////////////////// Start exeQuery Function //////////////////
public function exeQuery($qry) {
echo $qry;
try {
$res = mysql_query($qry, $this->utilLink);
if(!is_resource($res) || (!$res)) {
$res=false;
} else {
$numRows = mysql_num_rows($res);
if($numRows<=0) {
$res=false;
}
}
return $res;
}
catch(Exception $ee){
return (false);
}
}
////////////////// End exeQuery Function //////////////////
////////////////// Start closeCon Function //////////////////
public function closeCon() {
mysql_close($this->utilLink);
}
////////////////// End closeCon Function //////////////////
#----------------------------Start Utility Function ------------------#
public function __destruct() {
if($this->utilAns==true) {
$this->closeCon();}
}
}
?>
code: save file UtilClass.php
<?php
include_once("UtilClass.php");
class classes1 extends UtilClass {
var $host;
var $db ;
var $user;
var $pass;
var $link,$isDBConnect;
var $isError,$errorValue;
var $dt;
var $adminEmail,$adminMobile,$adminEmailPass,$adminEmailPort,$adminEmailHost,$scrollText;
function __construct() {
parent::__construct();
$this->host = parent::getHost();
$this->db = parent::getDb();
$this->user = parent::getUser();
$this->pass = parent::getPass();
try {
$this->link = mysql_connect($this->host, $this->user, $this->pass);
if (!is_resource($this->link)) {
$this->isDBConnect=false;
}
else {
$this->isDBConnect=true;
}
mysql_select_db($this->db,$this->link);
$this->getAdminAllInfo();
}
catch(Exception $ee){
$this->link=false;
}
}
public function setCon() {
$this->host = parent::getHost();
$this->db = parent::getDb();
$this->user = parent::getUser();
$this->pass = parent::getPass();
try {
$this->link = mysql_connect($this->host, $this->user, $this->pass);
if (!is_resource($this->link)) {
$this->isDBConnect=FALSE;
}
else {
$this->isDBConnect=TRUE;
}
mysql_select_db($this->db,$this->link);
}
catch(Exception $ee){
$this->link=FALSE;
}
}
public function getTotalRecord($table) {
$res=false;
$sSql="SELECT COUNT(*) AS total FROM $table";
try {
$rs=$this->exeQuery($sSql);
if($rs) {
$fQury=mysql_fetch_array($rs);
return $fQury['total'];
}
else { return 0; }
} catch(Exception $ee){
$res=false;
}
return $res;
}
public function activeDeactive($ID,$isActive,$tb, $colName) {
$ans="No";
$sSql="Update $tb set isActive=$isActive where $colName=$ID";
try {
$rs=$this->exeQuery($sSql);
if($rs) {
$ans="Yes";
} else { $ans="No"; }
} catch(Exception $ee){
$ans="No";
}
echo $ans;
}
public function deleteRecord($ID,$tb,$colName) {
$ans="No";
$sSql="delete from $tb where $colName=$ID";
try {
$rs=$this->exeQuery($sSql);
if($rs) {
$ans="Yes";
//unlink("../images/$dr/$ID.jpg");
} else { $ans="No"; }
} catch(Exception $ee){
$ans="No";
}
echo $ans;
}
///////////////////////////////////////////////////////////////////////////////////////////
public function exeQuery($query) {
$res=false;
try {
$res = mysql_query($query, $this->link);
}
catch(Exception $ee){
$res=false;
}
return $res;
}
public function getRow($res) {
$arr = @mysql_fetch_array($res, MYSQL_BOTH);
return $arr;
}
public function close() {
}
public function __destruct() {
mysql_close($this->link);
}
}
?>
No comments:
Post a Comment