Advertisement
terorama

mvc / setup.inc.php

Dec 22nd, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2.  
  3. //-------------------------------------------------
  4. //            setup model
  5. //-------------------------------------------------
  6. class Setup extends Model {
  7.  
  8.    private $sqls = array(
  9.    
  10.       //-----------------------------
  11.       'drop table if exists questions',
  12.       'drop table if exists users',
  13.       'drop table if exists categories',
  14.       'drop table if exists answers',
  15.      
  16.       //-----------------------------
  17.       'create table questions (
  18.          qid int(11) not null auto_increment,
  19.          quid int(11),
  20.          qtitle varchar(50),
  21.          qtext varchar(500),
  22.          qcategory int(11),
  23.          quser int(11),
  24.          qdate datetime,
  25.          primary key(`qid`)) ',
  26.          
  27.       //-----------------------------
  28.       'create table users (
  29.          uid int(11) not null auto_increment,
  30.          uname varchar(20),
  31.          upassword varchar(50),
  32.          uemail varchar(50),
  33.          udate datetime,
  34.          primary key(`uid`))',
  35.          
  36.       //-----------------------------
  37.       'create table categories (
  38.          cid int(11) not null auto_increment,
  39.          cname varchar(50),
  40.          primary key(`cid`))',
  41.          
  42.       //-----------------------------
  43.       'create table answers (
  44.          aid int(11) not null auto_increment,
  45.          aqid int(11),
  46.          auid int(11),
  47.          atext varchar(500),
  48.          adate datetime,
  49.          primary key(`aid`))'
  50.       );
  51.  
  52.    //--------------------------------   set auto vars
  53.    protected function setAutoVars() {
  54.    }
  55.      
  56.    
  57.    //-----------------------   create database tables
  58.    
  59.    public function createTables() {
  60.    
  61.       for ($i=0; $i<count($this->sqls); $i++) {
  62.      
  63.          $errors = array();
  64.          
  65.          $rez = $this->_db->query($this->sqls[$i]);
  66.          
  67.          if ($rez===false) {
  68.             $errors[] ='error '.$this->_db->error.'<br/> while executing: '.$this->sqls[$i];
  69.          }
  70.       }
  71.      
  72.       return (count($errors)>0) ? implode('<br/><br/>', $errors) : 'operation completed';
  73.      
  74.    }
  75.    
  76. }
  77.  
  78.  
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement