subversion://[vpntest]/release/2.0/WWW/lib/init.php Log in
ViewVC logotype

Annotate of /release/2.0/WWW/lib/init.php

Parent Directory Parent Directory | Revision Log Revision Log

Revision 9 - (show annotations) (download) (as text)
Sun Feb 17 15:07:41 2008 MSK (12 years, 9 months ago) by vitalif
File MIME type: text/x-php; charset=windows-1251
File size: 2108 byte(s)
Release 2.0

1 <?php
2
3 // Функция инициализации БД
4 // Copyright (c) 2006, Виталий Филиппов [VMX]
5
6 require_once 'config.php';
7
8 function init_database ()
9 {
10 global $result, $UsersTable, $QuestionsTable, $ResultsTable, $db;
11 // БД
12 $result = amysql_query ("CREATE DATABASE IF NOT EXISTS `$db` DEFAULT CHARACTER SET cp1251 COLLATE cp1251_general_ci");
13 if (!$result) return false;
14 if (!mysql_select_db ($db)) return false;
15 // Таблица пользователей
16 $result = amysql_query ("DROP TABLE IF EXISTS `$UsersTable`");
17 if (!$result) return false;
18 $result = amysql_query ("CREATE TABLE IF NOT EXISTS `$UsersTable` (`id` int(11) NOT NULL auto_increment, `login` text NOT NULL, `password` text NOT NULL, `level` int(11) default NULL, `testlimit` int(11) default NULL, `firstname` text NOT NULL, `lastname` text NOT NULL, `thirdname` text NOT NULL, `town` text NOT NULL, `firm` text NOT NULL, `position` text NOT NULL, `email` text NOT NULL, `phone` text NOT NULL, `vipnet` text NOT NULL, `date` date NOT NULL, `time` time NOT NULL, PRIMARY KEY `id` (`id`)) AUTO_INCREMENT=1");
19 if (!$result) return false;
20 // Таблица вопросов
21 $result = amysql_query ("DROP TABLE IF EXISTS `$QuestionsTable`");
22 if (!$result) return false;
23 $result = amysql_query ("CREATE TABLE IF NOT EXISTS `$QuestionsTable` (`id` int(11) NOT NULL auto_increment, `num` int(11) NOT NULL, `varid` int(11) default NULL, `question` text NOT NULL, `answer1` text NOT NULL, `answer2` text NOT NULL, `answer3` text NOT NULL, `answer4` text NOT NULL, `rightanswer` int(11) default NULL, PRIMARY KEY `id` (`id`)) AUTO_INCREMENT=1");
24 if (!$result) return false;
25 // Таблица результатов
26 $result = amysql_query ("DROP TABLE IF EXISTS `$ResultsTable`");
27 if (!$result) return false;
28 $result = amysql_query ("CREATE TABLE IF NOT EXISTS `$ResultsTable` (`id` int(11) NOT NULL auto_increment, `uid` int(11) default NULL, `varid` int(11) default NULL, `date` DATE NOT NULL, `time` TIME NOT NULL, `answers` text NOT NULL, `result` int(11) default NULL, PRIMARY KEY `id` (`id`)) AUTO_INCREMENT=1");
29 if (!$result) return false;
30 return true;
31 }
32
33 ?>