php类似数据库方法链接拼接语句类
本想写个PHP的适合自己的简单框架,感觉又有大多东西要折腾,所以迟迟没动手。
闲来无事,就写了一数据库的测试类,写的比较粗糙,不喜勿喷,以本人自己的想法实现数据链接组合sql语句的类,供大家查考,如果有更好的方法可以贴出来,在下不胜感激。
Class Db
{
protected static $query;
protected static $instance;
protected static $table;
protected static $where;
public static function instance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
public static function table($t)
{
self::$table = $t;
return self::instance();
}
public static function where($w)
{
self::$where = $w;
return self::instance();
}
public static function select()
{
self::$query = "SELECT * FROM " . self::$table . " WHERE " . self::$where;
return self::$query;
}
}
$res = Db::table('tb_test')->where(' AND id=1')->select();
var_dump($res);本文作者: Liaodeity
本文链接: https://www.jianbaizhan.com/article/516
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!