Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //-------------------------------------------------
- // setup model
- //-------------------------------------------------
- class Setup extends Model {
- private $sqls = array(
- //-----------------------------
- 'drop table if exists questions',
- 'drop table if exists users',
- 'drop table if exists categories',
- 'drop table if exists answers',
- //-----------------------------
- 'create table questions (
- qid int(11) not null auto_increment,
- quid int(11),
- qtitle varchar(50),
- qtext varchar(500),
- qcategory int(11),
- quser int(11),
- qdate datetime,
- primary key(`qid`)) ',
- //-----------------------------
- 'create table users (
- uid int(11) not null auto_increment,
- uname varchar(20),
- upassword varchar(50),
- uemail varchar(50),
- udate datetime,
- primary key(`uid`))',
- //-----------------------------
- 'create table categories (
- cid int(11) not null auto_increment,
- cname varchar(50),
- primary key(`cid`))',
- //-----------------------------
- 'create table answers (
- aid int(11) not null auto_increment,
- aqid int(11),
- auid int(11),
- atext varchar(500),
- adate datetime,
- primary key(`aid`))'
- );
- //-------------------------------- set auto vars
- protected function setAutoVars() {
- }
- //----------------------- create database tables
- public function createTables() {
- for ($i=0; $i<count($this->sqls); $i++) {
- $errors = array();
- $rez = $this->_db->query($this->sqls[$i]);
- if ($rez===false) {
- $errors[] ='error '.$this->_db->error.'<br/> while executing: '.$this->sqls[$i];
- }
- }
- return (count($errors)>0) ? implode('<br/><br/>', $errors) : 'operation completed';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement