Не помогло :(
Если это поможет, вот весь код файла:
<?php
class demand {
private $dbOptions;
private $randQuery;
private $countText;
private static $db = null;
public static function getDb()
{
if (null === self::$db)
self::$db = new self();
return self::$db;
}
private function __copy () {}
private function __construct ()
{
try
{
$this->dbOptions = config('db');
$this->db = new PDO('mysql:host='.$this->dbOptions['host'].';dbname='.$this->dbOptions['dbName'],$this->dbOptions['login'],$this->dbOptions['pass']);
$this->db->exec('SET NAMES utf8');
}
catch (PDOException $e)
{
die("Error: ".$e->getMessage());
}
}
function rand($limit='1')
{
$limit = veriNumber($limit);
$this->randQuery = 'ORDER BY RAND() LIMIT '.$limit;
}
function setCount()
{
$this->countText = 'count(1)';
}
function setWhere($where)
{
$this->where = $where;
}
function query($id,$table,$chain=false,$nameId='id',$column='*',$order='',$limit='')
{
if ($table=='manager') $table = 'users';
elseif ($table=='ban') $table = 'ban';
else $table = $this->dbOptions['prefix'].$table;
$where = '';
if (empty($this->where))
{
if ($id!='')
{
if (!is_array($id))
{
if (is_array($nameId))
{
$where = 'where ';
for ($i=0;$i<count($nameId);$i++)
{
$where .= '`'.$nameId[$i].'` = \''.my_esc($id).'\'';
if (!empty($nameId[$i+1])) $where .= ' or ';
}
}
else
if ($id=='0' || !empty($id)) $where = 'where `'.$nameId.'` = \''.my_esc($id).'\'';
}
else
{
$where = 'where ';
if (is_array($nameId))
{
for ($i=0;$i<count($id);$i++)
{
$where .= '`'.$nameId[$i].'` = \''.my_esc($id[$i]).'\'';
if (!empty($nameId[$i+1])) $where .= ' and ';
}
}
else
{
for ($i=0;$i<count($id);$i++)
{
$where .= '`'.$nameId.'` = \''.my_esc($id[$i]).'\'';
if (isset($id[$i+1])) $where .= ' or ';
}
}
}
}
}
else
{
$where = 'where '.$this->where;
$this->where = '';
}
if (!empty($limit)) $limit = 'limit '.$limit.'';
if (!empty($order)) $order = 'order by '.$order.'';
if (!empty($this->countText)) $column = $this->countText;
if (empty($this->randQuery)) $sth = $this->db->query('select '.$column.' from `'.$table.'` '.$where.' '.$order.' '.$limit.';');
else
{
$sth = $this->db->query('select '.$column.' from `'.$table.'` '.$where.' '.$this->randQuery.';');
$this->randQuery = '';
}
$fp = fopen("log.txt", "a");
$mytext = 'select '.$column.' from `'.$table.'` '.$where.' '.$order.' '.$limit.';<br/>';
$test = fwrite($fp, $mytext);
fclose($fp);
$result = array();
if (empty($this->countText))
{
$tt = explode ('_',$table);
if ($tt[0]=='users') $tt[1] = 'manager';
$sth->setFetchMode(PDO::FETCH_CLASS, $tt[1]);
while($obj = $sth->fetch())
{
if($chain!=false) $obj->addition($chain);
array_push($result,$obj);
}
}
else
{
$sth->setFetchMode(PDO::FETCH_NUM);
$result = $sth->fetch();
$this->countText = '';
}
return $result;
}
function update ($table,$column,$value,$id,$idName='id')
{
$data['column'] = my_esc($column);
if (is_array($value))
{
$stq = '';
foreach ($value as $key => $val)
{
$stq .= "`$key`='$val',";
}
$set = cutLastComma($stq);
}
else $data['value'] = my_esc($value);
$data['id'] = my_esc($id);
$data['idName'] = my_esc($idName);
if ($table!='manager') $data['table'] = my_esc($this->dbOptions['prefix'].$table);
else $data['table'] = 'users';
if (is_array($value))
{
$this->db->query("UPDATE `$data[table]` SET $set WHERE `$data[idName]` = '$data[id]'");
}
else $this->db->query("UPDATE `$data[table]` SET `$data[column]`='$data[value]' WHERE `$data[idName]` = '$data[id]'");
}
function salaryUpdate ($table,$column,$value,$id,$idName='id')
{
if (is_array($value))
{
$str = '';
foreach ($value as $key => $val)
{
$str .= "`$key`=$key-$val,";
}
$set = cutLastComma($str);
} else $data['value'] = my_esc($value);
$data['column'] = my_esc($column);
$data['id'] = my_esc($id);
$data['idName'] = my_esc($idName);
$data['table'] = my_esc($this->dbOptions['prefix'].$table);
if (is_array($value))
{
$this->db->query("UPDATE `$data[table]` SET $set WHERE `$data[idName]` = '$data[id]'");
} else $this->db->query("UPDATE `$data[table]` SET `$data[column]`= $data[column] - $data[value] WHERE `$data[idName]` = '$data[id]'");
}
function insert ($table,$columns,$values)
{
$data['column'] = '';
$data['value'] = '';
foreach ($columns as $column)
{
$data['column'] .= '`'.my_esc($column).'`,';
}
$data['column'] = substr($data['column'],0,strlen($data['column'])-1);
foreach ($values as $value)
{
$data['value'] .= '\''.my_esc($value).'\',';
}
$data['value'] = cutLastComma($data['value']);
$data['table'] = my_esc($this->dbOptions['prefix'].$table);
$this->db->query("INSERT INTO `$data[table]` ($data[column]) VALUES($data[value])");
}
function delete ($table,$where)
{
$data['where'] = '';
foreach ($where as $key=>$value)
{
if (!empty($data['where'])) $data['where'] .=" AND ";
$data['where'] .= '`'.my_esc($key).'`=\''.$value.'\'';
}
$data['table'] = my_esc($this->dbOptions['prefix'].$table);
$this->db->query("DELETE FROM `$data[table]` WHERE $data[where]");
}
}
?>