class template { VAR $files = array(); VAR $variables = array(); VAR $sql = array(); VAR $opening_escape = '{'; VAR $closing_escape = '}'; VAR $host = "localhost"; VAR $user = "root"; VAR $pswd = ""; VAR $db = "book"; VAR $address_table = "addressbook"; . . . function address_sql($file_id, $variable_name, $letter) { // Подключиться к серверу MySQL и выбрать базу данных mysql_connect($this->host, $this->user, $this->pswd) or die("Couldn't connect to MySQL server!"); mysql_select_db($this->db) or die("Couldn't select MySQL database!"); // Обратиться с запросом к базе данных $query = "SELECT last_name, first_name, tel, email FROM $this->address_table WHERE last_name LIKE '$letter%'"; $result = mysql_query($query); // Открыть файл "rows.addresses" // и прочитать его содержимое в переменную $fh = fopen("$variable_name", "r"); $file_contents = fread($fh, filesize("rows.addresses") ); // Заменить имена переменных в ограничителях // данными из базы. while ($row = mysql_fetch_array($result)) : $new_row = $file_contents; $new_row = str_replace($this->opening_escape."last_name".$this->closing_escape, $row["last_name"], $new_row); $new_row = str_replace($this->opening_escape."first_name".$this->closing_escape, $row["first_name"], $new_row); $new_row = str_replace($this->opening_escape."telephone".$this->closing_escape, $row["tel"], $new_row); $new_row = str_replace($this->opening_escape."email".$this->closing_escape, $row["email"], $new_row); // Присоединить запись к итоговой строке замены $complete_table .= $new_row; endwhile; $sql_array_key = $variable_name; $this->sql[$sql_array_key] = $complete_table; // Включить ключ в массив variables для последующего поиска $this->variables[$file_id][] = $variable_name; // Закрыть файловый манипулятор fclose($fh); } . . . }