如何重构它以进行单个函数调用?
我已经使用它一段时间了,根据需要更新 mysql。但是我不太确定语法......并且需要将 sql 迁移到数组。
这一行
database::query("CREATE TABLE $name($query)");
特别是“这是否翻译成
CREATE TABLE bookmark(name VARCHAR(64), url VARCHAR(256), tag VARCHAR(256), id INT)
这是我的……猜测” 。这是正确的吗?
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');
}
}
}
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');
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我明白你想说的话,你所要做的就是将
create()
方法中的代码更改为类似于make()
,使 < code>create() 具有make()
签名的公共方法,并从类中删除make()
方法:If I have understood what you want to say, all you have to do is change the code in the
create()
method to be similar to themake()
, makingcreate()
a public method with themake()
signature and removing themake()
method from the class: