| Server IP : 103.234.187.230 / Your IP : 216.73.216.216 Web Server : Apache System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/b2bzend/application/models/ |
Upload File : |
<?php
/**
* Copyright 2013 Catabatic Automation Technology Pvt Ltd.
* All rights reserved
*
* @description: BaseModel.php 2016/07/01 13:32
* @author: Shakti Rana <shakti@catpl.co.in>
*/
class BaseModel{
protected $db;
public function __construct(){
$request = Zend_Controller_Front::getInstance()->getRequest();
$this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
$this->db = Zend_Db_Table::getDefaultAdapter();
$this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
}
public function __destruct() {
$this->db->closeConnection();
}
/**
* Get Record by fieldname.
*
* @param type $columnName
* @param type $columnValue
* @param string $tableName
* @param boolean $isReturn
* @return array|int
*/
public function getRecord($columnName, $columnValue, $tableName, $isReturn = false)
{
$query = $isReturn ? array('*') : array('count(*) AS totalRecords');
$select = $this->db->select()
->from($tableName, $query)
->where($columnName.' =?', $columnValue);
$record = $this->db->fetchAll($select);
return $isReturn ? @$record[0] : @$record[0]['totalRecords'];
}
/**
* getAllRecords.
*
* @param string $tableName
* @param string $orderBy
* @return array
*/
public function getAllRecords($tableName, $condition=null)
{
return $this->db->query("SELECT * FROM $tableName $condition")->fetchAll();
}
/**
* Insert record
*
* @param array $record
* @param string $tableName
* @return int
*/
public function insertRecord($record, $tableName) {
try {
$this->db->insert($tableName, $record);
$rowId = $this->db->lastInsertId(@$tableName);
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return @$rowId ? $rowId : 0;
}
/**
* Update record
*
* @param array $record
* @param string $whereCondition
* @return int
*/
public function updateRecord($record, $whereCondition, $tableName) {
try {
//$isUpdated = $this->db->query($updateQuery);
$isUpdated = $this->db->update($tableName, $record, $whereCondition);
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return @$isUpdated ? $isUpdated : 0;
}
/**
* Delete record
* @param string $whereCondition
* @param string $tableName
* @return int
*/
public function deleteRecord($whereCondition, $tableName)
{
try {
//$this->db->delete();
$isDeleted = $this->db->update($tableName, array('IsActive'=>0), $whereCondition);
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return @$isDeleted ? $isDeleted : 0;
}
/**
* SetActiveDeactive. To set IsActive/IsDeactive record.
*
* @param string $whereCondition
* @param string $tableName
* @param int $isActive
* @return int
*/
public function setActiveDeactive_($whereCondition, $tableName, $isActive=0)
{
try
{
$isChanged = $this->db->update($tableName, array('IsActive'=>$isActive), $whereCondition);
}
catch (Exception $e)
{
die('There has been an error. ' . $e->getMessage());
}
return @$isChanged ? $isChanged : 0;
}
/**
* Sanitize Data.
*
* @param string $input_data
* @return string
*/
public function sanitize_data($input_data) {
$searchArr = array("document", "write", "alert", "%", "$", ";", "+", "|", "#", "<", ">", ")", "(", "'", "\'", ",", "AND", "JAVASCRIPT");
$input_data = str_replace("script", "", $input_data);
$input_data = str_replace("iframe", "", $input_data);
$input_data = str_replace($searchArr, "", $input_data);
return htmlentities(stripslashes($input_data), ENT_QUOTES);
}
}