error_reporting(0);
set_error_handler("myErrorHandler");
date_default_timezone_set("Asia/Calcutta");
require_once("active18/common/sql_memcache.php");
function myErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
if($errstr != "Trying to get property of non-object" && $errfile != "code-repository/active18code/active18/common/connection.php" && substr($errstr, 0, 19) != "Undefined variable:" && $errstr != "A session had already been started - ignoring session_start()" && substr($errstr, 0, 16) != "Undefined index:")
{
if(isset($_SERVER["HTTP_TRUE_CLIENT_IP"]))
$clientip = $_SERVER["HTTP_TRUE_CLIENT_IP"];
elseif(isset($_SERVER["HTTP_HTTP_NS_REMOTE_ADDR"]))
$clientip = $_SERVER["HTTP_HTTP_NS_REMOTE_ADDR"];
else
$clientip = $_SERVER["REMOTE_ADDR"];
$fp = fopen("/gfs-data/phplogs/phperror_" . date("Ymd") . ".csv", "a");
$data = '"' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . '","' . date("YmdHis") . '","' . $errno . '","' . str_replace('"', '\"', $errstr) . '","' . str_replace('"', '\"', $errfile) . '","' . $errline . '","' . str_replace('"', '\"', count($errcontext)) . '","' . $_SERVER["HTTP_REFERER"] . '","' . $clientip . '"' . chr(10);
$ret = fwrite($fp, $data, strlen($data));
fclose($fp);
}
return true;
}
class db
{
var $conn = array();
//var $rs;
//var $row;
var $lasterrno;
var $lasterrmsg;
function myconnect($db)
{ global $ud_arr;
//readnow cms
if($db == "inrevampdb")
{
//$host = "172.30.30.51";
$host = "172.30.254.189";
$user = "in-code-rw";
$pwd = "EDhdfjh58ayjioG";
//$db = "webdrive_0";
$db = "inrevampdb";
}
if($db == "liveusers")
{
//$host = "172.30.30.51";
$host = "172.30.254.41";
$user = "In_stg_lvu_rw";
$pwd = "Cmp123fdghf67RM";
$db = "liveusers";
}
elseif($db == "social")
{
$host = "172.30.254.42";
$user = "in_social_rw";
$pwd = "udf123gfgreuj67ASD";
$db = "social";
}
elseif($db == "storage")
{
//$host = "172.30.30.51";
$host = "172.30.254.42";
$user = "in_stg_attch_rw";
$pwd = "udf13gvr66eujASM";
//$db = "attachment";
$db = "attachment_0";
}
elseif($db == "oldstorage")
{
$host = "172.30.30.51";
$user = "in_stg_oattch_rw";
$pwd = "Drt_rt_MVsdstsdSD";
$db = "attachment";
}
elseif($db == "mail")
{
if(isset($ud_arr[2]))
{
$host = $ud_arr[1] . ".db.dc1.in.com";
$db = "mailbox_" . $ud_arr[2];
}
else
{
$host = "172.30.40.34";
$db = "mailbox_0";
}
$user = "in_stg_mbox_rw";
$pwd = "ASD1EcjhMrudf67gt";
//$user = "root";
//$pwd = "admin";
}
elseif($db == "mailflags")
{
if(isset($ud_arr[2]))
{
$host = str_replace(chr(10), '', $ud_arr[7]);
$db = "mailflags_" . $ud_arr[8];
$user = "in_stg_mflg_rw";
$pwd = "IN1EcjhMrudf67gtSTG";
}
else
{
$host = "172.30.30.51";
$db = "mailflags_0";
$user = "in_stg_mflg_rw";
$pwd = "IN1EcjhMrudf67gtSTG";
}
}
elseif($db == "web18mail")
{
$host = "172.30.254.41";
$user = "in_w18_mail_rw";
$pwd = "SD_rt_&*sdQWDpMzD";
$db = "web18mail";
}
elseif($db == "mailmetadata")
{
$host = "172.30.254.41";
$user = "in_stg_metad_rw";
$pwd = "FGK1EcjhMrudfCmR";
$db = "mailmetadata";
}
elseif($db == "webdrive")
{
//$host = "172.30.30.51";
$host = "172.30.254.42";
$user = "in_stg_driv_rw";
$pwd = "ASD123Wrudf67gt";
//$db = "webdrive_0";
$db = "webdrive_" . substr($ui, -1);
}
elseif($db == "classified")
{
if($_COOKIE["oms"] != "")
{
$host = hexstr(strrev(base64_decode($_COOKIE["oms"])));
}
else
{
//$host = "172.30.30.60";
$host = "172.30.30.51";
}
$user = "root";
$pwd = "admin";
$db = "classified";
}
elseif($db == "readnow"){
if($_COOKIE["oms"] != "")
{
$host = hexstr(strrev(base64_decode($_COOKIE["oms"])));
}
else
{
//$host = "172.30.254.44";
//$host = "172.30.11.37";
$host = "172.30.254.76";
}
$user = "in_read_rw";
$pwd = "wert_rt_&*sdstsdSD";
$db = "readnow";
}
elseif($db == "watchnow"){
if($_COOKIE["oms"] != "")
{
$host = hexstr(strrev(base64_decode($_COOKIE["oms"])));
}
else
{
//$host = "172.30.254.44";
//$host = "172.30.11.39";
$host = "172.30.254.77";
//$host = "localhost";
}
$user = "in_watch_rw";
$pwd = "qw_rt_&*sddfdSD";
$db = "watchnow";
}
elseif($db == "listennow")
{
if($_COOKIE["oms"] != "")
{
$host = hexstr(strrev(base64_decode($_COOKIE["oms"])));
}
else
{
//$host = "172.30.254.44";
//$host = "172.30.11.37";
$host = "172.30.254.76";
}
$user = "in_listen_rw";
$pwd = "gt123!^udf67AdD";
$db = "listennow";
}
elseif($db == "playnow")
{
if($_COOKIE["oms"] != "")
{
$host = hexstr(strrev(base64_decode($_COOKIE["oms"])));
}
else
{
//$host = "172.30.254.44";
//$host = "172.30.11.39";
$host = "172.30.254.77";
}
$user = "in_play_rw";
$pwd = "SD_rt_&*sddfsdSD";
$db = "playnow";
}elseif($db == "playnowwrite")
{
if($_COOKIE["oms"] != "")
{
$host = hexstr(strrev(base64_decode($_COOKIE["oms"])));
}
else
{
//$host = "172.30.254.44";
//$host = "172.30.11.39";
$host = "172.30.254.77";
}
$user = "in_play_rw";
$pwd = "SD_rt_&*sddfsdSD";
$db = "playnow";
}
$this->conn[0] = new mysqli($host, $user, $pwd, $db);
$this->conn[1] = $db;
if (mysqli_connect_errno())
{
errorlog(mysqli_connect_error(), mysqli_connect_errno());
//exit();
}//
return $conn;
}
function errorlog($errmsg, $errno)
{
//echo "ERROR:" . $errno . ":" . $errmsg;
$fp = fopen("/gfs-data/db_" . date("Ymd") . ".txt", "a");
$msg = $_SERVER["HTTP_HOST"] . "|" . date("YmdHis") . "|" . $errno . "|" . $errmsg . "|" . $sql . "\n";
$ret = fwrite($fp, $msg, strlen($msg));
fclose($fp);
}
function myfree()
{
$this->conn[0]->close();
unset($this->conn);
unset($this->lasterrno);
unset($this->lasterrmsg);
}
function strhex($string)
{
$hexstr = unpack('H*', $string);
return array_shift($hexstr);
}
function hexstr($hexstr)
{
$hexstr = str_replace(' ', '', $hexstr);
$retstr = pack('H*', $hexstr);
return $retstr;
}
}
class query
{
var $rs;
var $row;
var $rowcount;
var $insertid;
var $affectedcount;
var $errno;
var $errmsg;
var $hash;
var $rowno;
var $source;
function myquery($sql, $conn, $ttl = 120)
{
$cache = 0;
$this->source = 0;
$sql = trim($sql);
// echo "
SQL:" . $sql;
$this->hash = md5($conn[1] . $sql);
$this->rowno = 0;
//echo "
" . $sql;
$hash = md5($conn[1] . $sql);
if(strtolower(substr($sql, 0, 6)) == "select" && $ttl > 0)
{
//echo "1
";
if(is_array(getMem("sql_" . $hash)))
{
//echo "2
";
$daterange = date("YmdHis", mktime(date("H"), date("i"), date("s")-$ttl, date("m"), date("d"), date("Y")));
if(getMem("ttl_" . $hash) > $daterange)
{
// echo "3
";
$cache = 1;
}
}
}
if($cache == 0)
{
$this->source = 0;
$this->rs = $conn[0]->query($sql);
if (!$this->rs)
{
$this->errno = mysqli_errno($conn[0]);
$this->errmsg = mysqli_error($conn[0]);
//echo $this->errmsg;
$this->errorlog(mysqli_error($conn[0]), mysqli_errno($conn[0]), $sql);
//exit();
}
else
{
//if(strtolower(substr(trim($sql), 0, 6)) == "select")
$this->errno = 0;
$this->errmsg = "";
$this->rowcount = $this->rs->num_rows;
//else
// $this->rowcount = 0;
$this->insertid = $conn[0]->insert_id;
$this->affectedcount = $conn[0]->affected_rows;
//echo "6
" . $sql;
if(strtolower(substr($sql, 0, 6)) == "select")
{
//$memdata[] = $this->errno . "|" . $this->errmsg . "|" . $this->rowcount . "|" . $this->insertid . "|" . $this->affectedcount;
//echo "Cnt:" . $this->rowcount . "
";
if($this->rowcount > 0)
{
while($this->row = $this->rs->fetch_assoc())
{
/*$count = count($this->row);
$datastr = array();
for($ctr=0; $ctr < $count; $ctr++)
$datastr[$ctr] = $this->row[$ctr];
$memdata[] = $datastr;*/
$memdata[] = $this->row;
}
}
else
$memdata[] = " ";
//echo "DATA:";
//print_r($memdata);
//echo "RS:" . $this->rs . "
";
//setMem("sql_" . $hash, print_r($this->rs->fetch_array()));
setMem("sql_" . $hash, $memdata);
setMem("ttl_" . $hash, date("YmdHis"));
setMem("sqlvar_" . $hash, $this->errno . "|" . $this->errmsg . "|" . $this->rowcount . "|" . $this->insertid . "|" . $this->affectedcount);
unset($memdata);
}
}
}
else
{
//echo "5
";
$this->source = 1;
$data = explode("|", getMem("sqlvar_" . $this->hash));
$this->errno = $data[0];
$this->errmsg = $data[1];
$this->rowcount = $data[2];
$this->einsertid = $data[3];
$this->affectedcount = $data[4];
unset($data);
//$data = getMem("sql_" . $this->hash);
//$this->row = $data[$this->rowno];
//$this->rowno++;
//unset($data);
}
//echo "
Source:" . $this->source;
//echo "
SQL:" . $sql;
//echo "
ROW:" . $this->rowno . "
";
}
function myfetch()
{
//echo "H:" . $this->hash;
// echo "6
";
if($this->rowno < $this->rowcount)
{
$data = getMem("sql_" . $this->hash);
$this->row = $data[$this->rowno];
//print_r($this->row);
$this->rowno++;
unset($data);
return 1;
}
else
{
//echo "
EOF";
return 0;
}
/*if($this->row = $this->rs->fetch_array())
{
return 1;
}
else
{
return 0;
}*/
}
function myfree()
{
//$this->rs->free();
unset($this->rs);
unset($this->row);
unset($this->rowcount);
unset($this->affectedcount);
}
function errorlog($errmsg, $errno, $sql)
{
//echo "ERROR:" . $errno . ":" . $errmsg;
$fp = fopen("/gfs-data/db_" . date("Ymd") . ".txt", "a");
$msg = $_SERVER["HTTP_HOST"] . "|" . date("YmdHis") . "|" . $errno . "|" . $errmsg . "|" . $sql . "\n";
$ret = fwrite($fp, $msg, strlen($msg));
fclose($fp);
}
}
/*function api_reader($logreaddocid,$logreadclusterid,$logreadflag,$logreaduserid){
$m_mysql= new db();
$m_mysql->myconnect("social");
switch ($logreadflag){
case 1:
if ($logreadflag=="listen"){
$logreadurl="/active18/readnow/storypage.php?docid=".$logreaddocid."&flag=listen";
}else if($logreadclusterid!=''){
$logreadurl="/active18/readnow/storypage.php?docid=".$logreaddocid."&clustid=".$logreadclusterid;
}
break;
case 2:
$loglistenurl="/active18/readnow/myfeedstorydetail.php?storyid=".$logreaddocid;
break;
}
$m_sql_select=new query();
$sql_select="select urlid from readurl where url='$logreadurl'";
$m_sql_select->myquery($sql_select, $m_mysql->conn);
$m_sql_select->myfetch();
$logreadurlid=$m_sql_select->row['urlid'];
$logreaduserdb=substr($logreaduserid,-1);
$logreadenddate=date('Ymd');
$m_sql=new query();
$sql ="insert into readlogs_".$logreaduserdb." values('','$logreaduserid','$logreadurlid','$logreadenddate','$logreadcategoryid')";
$m_sql->myquery($sql, $m_mysql->conn);
//echo "
Return data=".$m_sql->insertid; $m_sql->myfree(); $m_mysql->myfree(); }*/ ?>