how do I refactor this to make single function calls?

Posted by stack.user.1 on Stack Overflow See other posts from Stack Overflow or by stack.user.1
Published on 2011-11-19T00:11:18Z Indexed on 2011/11/19 1:50 UTC
Read the original article Hit count: 95

Filed under:
|

I've been using this for a while updating mysql as needed. However I'm not too sure on the syntax..and need to migrate the sql to an array.

Particulary the line

database::query("CREATE TABLE $name($query)");

Does this translate to

CREATE TABLE bookmark(name VARCHAR(64), url VARCHAR(256), tag VARCHAR(256), id INT)

This is my ...guess. Is this correct?

class table extends database
{
    private function create($name, $query)
    {
        database::query("CREATE TABLE $name($query)");
    }

    public function make($type)
    {
        switch ($type) 
        {
            case "credentials":
                self::create('credentials', 'id INT NOT NULL AUTO_INCREMENT, flname VARCHAR(60), email VARCHAR(32), pass VARCHAR(40), PRIMARY KEY(id)');
                break;
            case "booomark":
                self::create('boomark', 'name VARCHAR(64), url VARCHAR(256), tag VARCHAR(256), id INT');
                break;
            case "tweet":
                self::create('tweet', 'time INT, fname VARCHAR(32), message VARCHAR(128), email VARCHAR(64)');
                break;
            default:
                throw new Exception('Invalid Table Type');
        }
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql