| Current Path : /var/www/html/app/code/FlipsDigital/HappyMind/Cron/ |
| Current File : /var/www/html/app/code/FlipsDigital/HappyMind/Cron/AbstractCron.php |
<?php
namespace FlipsDigital\HappyMind\Cron;
use \Zend\Log\Writer\Stream;
use \Zend\Log\Logger;
abstract class AbstractCron
{
protected $_className = __CLASS__;
protected $_logger;
protected $_connection;
protected $_objectManager;
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManagerInterface
) {
$this->_objectManager = $objectManagerInterface;
$arrClassName = explode('\\', $this->_className);
$logFile = BP . '/var/log/cron' . array_pop($arrClassName) . '.log';
$writer = new Stream($logFile);
$this->_logger = new Logger();
$this->_logger->addWriter($writer);
$serverName = "192.168.102.1";
$connectionInfo = array(
"Database"=>"MERS_STOCK",
"UID"=>"magento",
"PWD"=>"Magento888",
"CharacterSet"=>"UTF-8"
);
$this->_connection = sqlsrv_connect( $serverName, $connectionInfo);
if( $this->_connection === false ) {
$this->_logger->err("Connection failed: " . print_r( sqlsrv_errors(), true));
}
}
public function _executeQuery($sql, $params = []){
$stmt = sqlsrv_query( $this->_connection, $sql, $params);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
return $stmt;
}
public function _executeFetchArray($sql, $params = []){
$stmt = $this->_executeQuery($sql, $params);
$arrData = array();
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$arrData[] = $row;
}
sqlsrv_free_stmt($stmt);
return $arrData;
}
public function _getObjectManager($objecClass){
return $this->_objectManager->create($objecClass);
}
}