在类中使用变量

编程入门 行业动态 更新时间:2024-10-27 04:24:04
本文介绍了在类中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写了一个简单的类,它将MySQL SELECT查询放在一起, 允许你扩展查询,但我不确定何时使用$ this - > var_name,当我可以使用$ varname时,以及何时需要使用 ''var $ varname'',当这可以省略时。 这是'班级 - 可以变得更简单吗? Michael class select_query_builder { //放在一起并添加到选择查询的类 var $ query; var $ select; var $ from ; var $ where; var $ orderby; var $ distinct; var $ t_select; var $ t_from; var $ t_where; var $ t_orderby; 函数select_query_builder( $ select,$ from,$ where ='''',$ orderby =''''){ //每个变量都是一个数组 $ this - > select = $ select; $ this - > from = $ from; $ this - > where = $ where; $ this - > orderby = $ orderby; $ this - > t_select = $ select; $ this - > t_from = $ from; $ this - > t_where = $ where; $ this - > t_orderby = $ orderby; } //在查询中添加其他元素 函数extend_query($ what,$ newinfo ) { $ this - > {'t _''。$ what} = array_merge($ this - > {''t _''。$ what},$ newinfo); } //返回完整的查询; 函数return_query(){ $ this - > query =''SELECT''$ this - >不同。''''.implode('','',$ this - > t_select)。''FROM''。implode('','',$ this - > t_from); if(!empty($ this - > t_where)){ $ this - >查询。=''在哪里'.implode(''AND'',$ this - > t_where); } if(!empty ($ this - > orderby)){ $ this - > query。=''ORDER BY''。implode(''ASC,'',$ this - > t_orderby)。'' ASC''; } 返回$ this - >查询; } 函数reset_to_before_extend(){ $ this - > t_select = $ this - >选择; $ this - > t_from = $ this - >来自; $ this - > t_where = $ this - > where; $ this - > t_orderby = $ this - > orderby; } }

I''ve written a simple class that puts together a MySQL SELECT query and allows you to extend the query, but I''m unsure as to when to use $this - > var_name and when I can just use $varname, and when it''s necessary to use ''var $varname'' and when this can be left out. Here''s the class - could it be made simpler? Michael class select_query_builder { // class to put together and add to a select query var $query; var $select; var $from; var $where; var $orderby; var $distinct; var $t_select; var $t_from; var $t_where; var $t_orderby; function select_query_builder($select, $from, $where='''', $orderby ='''') { // each variable is an array $this -> select = $select; $this -> from = $from; $this -> where = $where; $this -> orderby = $orderby; $this -> t_select = $select; $this -> t_from = $from; $this -> t_where = $where; $this -> t_orderby = $orderby; } // add additional elements to the query function extend_query($what, $newinfo) { $this -> {''t_''.$what} = array_merge($this -> {''t_''.$what}, $newinfo); } // return the complete query; function return_query() { $this -> query = ''SELECT ''$this -> distinct.'' ''.implode('', '', $this -> t_select).'' FROM ''.implode('', '', $this -> t_from); if (!empty($this -> t_where)) { $this -> query .= '' WHERE ''.implode('' AND '', $this -> t_where); } if (!empty($this -> orderby)) { $this -> query .= '' ORDER BY ''.implode('' ASC, '', $this -> t_orderby).'' ASC''; } return $this -> query; } function reset_to_before_extend() { $this -> t_select = $this -> select; $this -> t_from = $this -> from; $this -> t_where = $this -> where; $this -> t_orderby = $this -> orderby; } }

推荐答案

this - > var_name当我可以使用 this - > var_name and when I can just use

varname时,以及何时需要使用 ''var varname, and when it''s necessary to use ''var

varname''什么时候可以省略。 这里是班级 - 可以变得更简单吗? Michael class select_query_builder { //要放在一起并添加到选择查询的类 var varname'' and when this can be left out. Here''s the class - could it be made simpler? Michael class select_query_builder { // class to put together and add to a select query var

更多推荐

在类中使用变量

本文发布于:2023-07-26 07:05:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1214866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   类中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!