上篇文章给大家介绍了《如何运用php进行数据库操作类?》,本文继续给大家介绍在php中数据库的查询方法应该如何实现??有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
查询方法应该如何实现:我们根据以前所讲的原理,我们需要用到以下方法:
//filed方法
//table方法
/ /where方法
//group方法
/ /having方法
//order方法
//limit方法
,如果说我们调用了其中的一个,那么我就会将其中的一个保存到一个数组中,最终我们通过select方法查询,最后将结果返回给我们,接下来我们就可以,以代码的形式呈现,代码如下:
我们先定义一个(function)函数;我们通过field方法,当传递过来以后,我们要判断,field是否传递了,如果不为空,我们会继续往下传递,如果为空,我们则直接返回$this,意思就是如果不为空,再进行处理,
//field 方法:
function field($field){//如果不为空,再进行处理if (!empty($field)) {if (is_ string($field)) {$this->options['field'] = $field;} else if (is_ array($field)) {$this->options['field'] = join(',', $field);}}return $this;}
//table方法:
一样的首先我们也是要判断是否为空;
function table($table ){if(!empty ($table)) {$this->options['table'] = $table;}return $this;}//where方法function where ($where ){if (!empty($where)) {$this->options[ 'where'] = 'where '.$where ;}return $this;}
//group方法
function group($group) if (!empty($group)) {$this- >options[ ' group'] ='group by '.$group;}return $this;}//having方法function having($having){if (!empty ($having)) {$this ->options['having'] = 'having'.$having;}return $this;}
//order方法
function order($order){if (!empty($order)) {$this->options['order'] = 'order by'.$order;}return $thiys;}
//limit方法
function limit($limit ){if (!empty($limit)) {if (is_string($limit)) {$this->options['limit'] ='limit'.$limit;} else if (is_array($limit)) {$this->options['limit'] = 'limit' . join(',',$limit);}}}
以上就是我们对外公开的一些方法;
推荐教程:《mysql教程》
以上就是在php中数据库的查询方法应该如何实现?的详细内容。