agent; public function __construct() { global $agent; $pdo = new MysqlPdo(hst, ndb, user, pass); $sql = "SET NAMES 'utf8'"; $pdo->query($sql); $this->db = $pdo; $this->agent = $agent; } public function set_sphinx2(){ $pdo = new MysqlPdo(hstsph2, null, null, null, true, '9306'); $sql = "SET NAMES 'utf8'"; $pdo->query($sql); $this->sphinx2 = $pdo; } public function arrToString($array) { return implode(',', array_map('intval', $array)); } public function insert($insertData) { $fields = []; $values = []; foreach ($insertData as $key => $value) { $fields[] = $key; // Если ключ properties, то проверяем, что это массив и кодируем его в JSON if ($key === 'properties' && is_array($value)) { $values[] = "'" . addslashes(json_encode($value, JSON_UNESCAPED_UNICODE)) . "'"; } else { $values[] = '"' . addslashes($value) . '"'; } } $fields = implode(', ', $fields); $values = implode(', ', $values); $sql = "INSERT INTO $this->table_name ($fields) VALUES ($values)"; return $this->db->query($sql); } public function update($updateData, $conditions) { $setValues = []; $whereConditions = []; // Формирование полей для обновления foreach ($updateData as $key => $value) { if ($key === 'properties' && is_array($value)) { $setValues[] = $key . " = '" . addslashes(json_encode($value, JSON_UNESCAPED_UNICODE)) . "'"; } else { $setValues[] = $key . " = \"" . addslashes($value) . "\""; } } // Формирование условий для WHERE foreach ($conditions as $field => $value) { $whereConditions[] = $field . " = \"" . addslashes($value) . "\""; } // Объединяем части $setValues = implode(', ', $setValues); $whereClause = implode(' AND ', $whereConditions); // Соединяем условия с 'AND' // Построение запроса $sql = "UPDATE $this->table_name SET $setValues WHERE $whereClause"; return $this->db->query($sql); } // public function delete($deleteData) { // } public function agent() { global $agent; return $this.$agent; } }