Overview

Namespaces

  • zsql
  • PHP

Classes

  • Database
  • Delete
  • Expression
  • ExtendedQuery
  • Insert
  • Model
  • Query
  • Result
  • Select
  • Update

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace zsql;
 4: 
 5: /**
 6:  * Update query generator
 7:  */
 8: class Update extends ExtendedQuery
 9: {
10:   /**
11:    * Values
12:    * 
13:    * @var array
14:    */
15:   protected $values;
16:   
17:   /**
18:    * Assemble parts
19:    * 
20:    * @return void
21:    */
22:   protected function assemble()
23:   {
24:     $this->push('UPDATE')
25:          ->pushTable()
26:          ->push('SET')
27:          ->pushValues()
28:          ->pushWhere()
29:          ->pushOrder()
30:          ->pushLimit();
31:   }
32:   
33:   /**
34:    * Alias for {@link Update::value()} or {@link Update::values()}
35:    * 
36:    * @param mixed $key
37:    * @param mixed $value
38:    * @return \zsql\Update
39:    */
40:   public function set($key, $value = null)
41:   {
42:     if( is_array($key) ) {
43:       return $this->values($key);
44:     } else {
45:       return $this->value($key, $value);
46:     }
47:   }
48:   
49:   /**
50:    * Alias for {@link Update::table()} and {@link Update::values()}
51:    * 
52:    * @param string $table
53:    * @param array $values
54:    * @return \zsql\Update
55:    */
56:   public function update($table, array $values = null)
57:   {
58:     $this->table($table);
59:     if( !empty($values) ) {
60:       $this->values($values);
61:     }
62:     return $this;
63:   }
64:   
65:   /**
66:    * Set a value
67:    * 
68:    * @param mixed $key
69:    * @param mixed $value
70:    * @return \zsql\Update
71:    */
72:   public function value($key, $value = null)
73:   {
74:     if( null === $value && $key instanceof Expression ) {
75:       $this->values[] = $key;
76:     } else {
77:       $this->values[$key] = $value;
78:     }
79:     return $this;
80:   }
81:   
82:   /**
83:    * Set values
84:    * 
85:    * @param array $values
86:    * @return \zsql\Update
87:    */
88:   public function values(array $values)
89:   {
90:     $this->values = $values;
91:     return $this;
92:   }
93: }
94: 
API documentation generated by ApiGen 2.8.0