Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class mysqlquery extends query implements iquery

Hide Inherited MembersHelix Core
Description
No description.
 
Constants
No constants.
 
Properties
protected_dirty[ obj ]
public_limit[ query ]
public_offset[ query ]
public_originalquery[ query ]
publicproperty_objects_array[ obj ]
public_query[ query ]
 
Methods
publicclean_query ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
098  public function clean_query()
099  {
100      $this->query = preg_replace('/[\r\n]+/i',' ',trim($this->query));
101      return $this;
102  }
public__construct ( query )[ query ]
Parameters
requiredquery
Code
009  public function __construct($__query){
010      $this->originalquery = $__query;
011      $this->query = $__query;
012      $this->clean_query();
013      $this->limit = $this->has_limit();
014      $this->offset = $this->has_offset();       
015  }
publicexecute ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
004  public function execute(){
005      return new recordset();
006  }
public__get ( p )[ obj ]
Parameters
requiredp
Code
007  public function __get($p)
008  {
009      $methods = get_class_methods($this);
010      $properties = get_object_vars($this);
011      if (in_array("get_$p",$methods))
012      {
013          return $this->{"get_$p"}();
014      }
015      else if (array_key_exists("_$p",$properties))
016      {
017          return $this->{"_$p"};
018      }
019      else if (in_array("get_" . substr($p,strpos($p,"_")+1), $methods))
020      {
021          return $this->{"get_" . substr($p,strpos($p,"_")+1)}(substr($p,0,strpos($p,"_")));
022      }
023      else
024      {
025          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
026          return null;
027      }
028  }
publicget_array ( )[ obj ]
Parameters
No parameters for this method
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicget_classname ( )[ obj ]
Parameters
No parameters for this method
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicget_dirty ( )[ obj ]
Parameters
No parameters for this method
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicget_json ( )[ obj ]
Parameters
No parameters for this method
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicget_properties ( )[ obj ]
Parameters
No parameters for this method
Code
121  public function get_properties()
122  {
123      return array_keys($this->array);
124  }
protectedget_string ( )[ obj ]
Parameters
No parameters for this method
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
publichas_limit ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
114  public function has_limit()
115  {
116      $matches = array();
117      preg_match('/limit +([0-9]+)( *, *([0-9]+))?[^a-z]*$/i',$this->query,$matches);
118     
119      if (count($matches)==0)
120      {
121          return false;
122      }
123      if (count($matches)==2)
124      {
125          //$query_offset = 0;
126          $query_limit = $matches[1];
127          return $query_limit;
128      }
129      else if (count($matches)==4)
130      {
131          //$query_offset = $matches[1];
132          $query_limit = $matches[3];
133          return $query_limit;
134      }
135      return false;
136  }
publichas_offset ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
138  public function has_offset()
139  {
140      $matches = array();
141      preg_match('/limit +([0-9]+)( *, *([0-9]+))?[^a-z]*$/i',$this->query,$matches);
142     
143      if (count($matches)==0)
144      {
145          return false;
146      }
147      if (count($matches)==2)
148      {
149          return false;
150      }
151      else if (count($matches)==4)
152      {
153          $query_offset = $matches[1];
154          //$query_limit = $matches[3];
155          return $query_offset;
156      }
157      return false;
158  }
publichas_order_by ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
109  public function has_order_by()
110  {
111      return preg_match('/order[\s\r\n]+by/i',$this->query);       
112  }
publicis_select ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
104  public function is_select()
105  {
106      return preg_match('/[\s\r\n]*select/i',$this->query);
107  }
publicorder_query ( order_by )[ mysqlquery ]
Parameters
optionalorder_by
Code
066  public function order_query($__order_by=null)
067  {
068      if ($this->is_select($this->query) && strlen(trim($__order_by))>0 && !$this->has_order_by())
069      {
070          if (is_string($__order_by))
071          {
072              $order_by = " ORDER BY {$__order_by} ";
073          }
074          else if (is_array($__order_by))
075          {
076              $order_by_columns = array();
077              foreach ($__order_by as $col=>$dir) {
078                  $dir = preg_match('/^(asc|desc)$/i',$dir) ? $dir : null;
079                  $order_by_columns[] = "{$col} {$dir}";
080              }
081              $order_by = " ORDER BY " . implode(",",$order_by_columns) . " ";
082          }
083         
084          if ($this->has_limit())
085          {
086              $matches = array();
087              preg_match('/limit +([0-9]+)( *, *([0-9]+))?[^a-z]*$/i',$this->query,$matches);
088              $this->query = preg_replace('/limit +([0-9]+)( *, *([0-9]+))?[^a-z0-9]*$/i',"{$order_by} $0",$this->query);
089          }
090          else
091          {
092              $this->query .= $order_by;
093          }
094      }
095      return $this;
096  }
publicpage_query ( limit , offset )[ mysqlquery ]
Parameters
optionallimit
optionaloffset
Code
008  public function page_query($__limit=null,$__offset=null)
009  {
010      if (!is_null($__limit))
011      {
012          $page_offset = alt($__offset,0);
013          $page_limit = alt($__limit,1);
014         
015          if ($this->is_select())
016          {
017              if($this->limit)
018              {
019                  $limit = min($page_limit,$this->limit);
020              }
021              else
022              {
023                  $limit = $page_limit;
024              }
025             
026              if($this->offset)
027              {
028                  $offset = $page_offset + $this->offset;
029              }
030              else
031              {
032                  $offset = $page_offset;
033              }
034             
035              if(!$this->limit&&!$this->offset)
036              {
037                  $this->query .= " LIMIT {$offset},{$limit} ";
038              }
039              else
040              {
041                  $this->query = preg_replace('/limit +([0-9]+)( *, *([0-9]+))?[^a-z0-9]*$/i'," LIMIT {$offset},{$limit} ",$this->query);
042              }
043          }
044      }
045      return $this;
046  }
public__set ( p , v )[ obj ]
Parameters
requiredp
requiredv
Code
030  public function __set($p,$v)
031  {
032      $methods = get_class_methods($this);
033      $properties = get_object_vars($this);
034      if (in_array("set_$p",$methods))
035      {
036          $this->{"set_$p"}($v);
037      }
038      else if (array_key_exists("_$p",$properties))
039      {
040          if (!preg_match('/_dirty$/',$p) && property_exists($this,"_{$p}_dirty"))
041          {
042              if (is_object($this->{"_$p"}))
043              {
044                  $this->{"_$p"}->dirty = true;
045              }
046              else
047              {
048                  $this->{"_{$p}_dirty"} = $this->{$p}==$v ? false : true;
049              }
050          }
051          $this->{"_$p"} = $v;
052      }
053      else if (in_array("set_" . substr($p,strpos($p,"_")+1), $methods))
054      {
055          $this->{"set_" . substr($p,strpos($p,"_")+1)}($v,substr($p,0,strpos($p,"_")));
056      }
057      else
058      {
059          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
060      }
061  }
publicsqlcalcrows_query ( )[ mysqlquery ]
Parameters
No parameters for this method
Code
048  public function sqlcalcrows_query()
049  {
050      if(!stristr($this->query,'SQL_CALC_FOUND_ROWS'))
051      {
052          $this->query preg_replace('/select/i','SELECT SQL_CALC_FOUND_ROWS',$this->query);
053      }
054      return $this;
055  }
 
Accessors
publicarray[ obj ]
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicclassname[ obj ]
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicdirty[ obj ]
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicjson[ obj ]
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicproperties[ obj ]
Code
121  public function get_properties()
122  {
123      return array_keys($this->array);
124  }
publicstring[ obj ]
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads