| 13 | + | INSERT INTO `test` (`id`, `name`) VALUES ('1', 'hoge') |
---|
| 14 | + | ** コンストラクタ [#ulEBVHO] |
---|
| 15 | + | :引数|string|TableIdentifier $table |
---|
| 16 | + | |
---|
| 17 | + | テーブル名を指定する、intoメソッドが優先される |
---|
| 18 | + | #sh(php){$insert=$sql->insert("test");} |
---|
| 19 | + | |
---|
| 20 | + | ** intoメソッド [#5bfgHXP] |
---|
| 21 | + | :引数|string|TableIdentifier $table |
---|
| 22 | + | |
---|
| 23 | + | テーブル名を指定する |
---|
| 24 | + | #sh(php){$insert->into("test");} |
---|
| 25 | + | |
---|
| 26 | + | ** columns [#6tEUBn8] |
---|
| 27 | + | :引数|array $columns |
---|
| 28 | + | |
---|
| 29 | + | カラム名を指定する。 |
---|
| 30 | + | &color(#FF0000){''Zend 2.3現在、columnsメソッドより後にvaluesメソッドを呼び出し、かつ第二引数にself::VALUES_SETを設定するか第二引数を省略した場合、columns設定値が消失する''}; |
---|
| 31 | + | #sh(php){{ |
---|
| 32 | + | $insert->columns(array("id", "name", "value")); |
---|
| 33 | + | }} |
---|
| 34 | + | |
---|
| 35 | + | ** values [#o66wZrF] |
---|
| 36 | + | :引数|array|Select $values |
---|
| 37 | + | string $flag VALUES_MERGE|VALUES_SET を指定、デフォルトはVALUES_SET |
---|
| 38 | + | |
---|
| 39 | + | Insertする値の設定を行う |
---|
| 40 | + | #sh(php){{ |
---|
| 41 | + | $insert->values(array("id"=>"1","name"=>"hoge")); |
---|
| 42 | + | }} |
---|
| 43 | + | |
---|
| 44 | + | |
---|
| 45 | + | ** select [#KMCZP0n] |
---|
| 46 | + | :引数|Select $select |
---|
| 47 | + | |
---|
| 48 | + | valuesメソッドが呼び出される。以下と全く同じである。 |
---|
| 49 | + | #sh(php){$insert->values($select);} |
---|
| 50 | + | |
---|
| 51 | + | |
---|
| 52 | + | ** getRawState [#sXaDmpJ] |
---|
| 53 | + | :引数|string $key |
---|
| 54 | + | |
---|
| 55 | + | table名、columns設定値、values設定値を返す。 |
---|
| 56 | + | #sh(php){{ |
---|
| 57 | + | // テーブル情報を返す |
---|
| 58 | + | $insert->getRawState("table"); |
---|
| 59 | + | // カラム名を返す |
---|
| 60 | + | $insert->getRawState("columns"); |
---|
| 61 | + | // values値を返す |
---|
| 62 | + | $insert->getRawState("values"); |
---|
| 63 | + | // 上記のすべてを連想配列で返す |
---|
| 64 | + | $insert->getRawState(); |
---|
| 65 | + | }} |
---|
| 66 | + | |
---|
| 67 | + | * Select [#8hdU3yM] |
---|
| 68 | + | Zend\Db\Sql\Sqlクラスのselectメソッドから呼び出される。 |
---|
| 69 | + | **基本的な利用方法 [#5ljzdHF] |
---|
| 70 | + | #sh(php){{ |
---|
| 71 | + | $sql = new Zend\Db\Sql\Sql($adapter); |
---|
| 72 | + | $select=$sql->select(); |
---|
| 73 | + | $select->from("test"); |
---|
| 74 | + | $select->columns(array("id"=>"rev_id", "name"=>"rev_name", "value"=>"rev_value")); |
---|
| 75 | + | $select->where(array("name"=>"yamada", "value > 100")); |
---|
| 76 | + | $select->limit(1); |
---|
| 77 | + | echo $sql->getSqlStringForSqlObject($select); |
---|
| 78 | + | }} |
---|
| 79 | + | SELECT `test`.`rev_id` AS `id`, `test`.`rev_name` AS `name`, `test`.`rev_value` AS `value` FROM `test` WHERE `name` = 'yamada' AND value > 100 LIMIT 1 |
---|
| 80 | + | ** コンストラクタ [#U0lUGlM] |
---|
| 81 | + | :引数|null|string|array|TableIdentifier $table |
---|
| 82 | + | |
---|
| 83 | + | テーブル名を指定する |
---|
| 84 | + | ここで指定するとread onlyになり、fromから指定できなくなる |
---|
| 85 | + | |
---|
| 86 | + | ** from [#vHKbmez] |
---|
| 87 | + | :引数|string|array|TableIdentifier $table |
---|
| 88 | + | |
---|
| 89 | + | テーブル名を指定する |
---|
| 90 | + | コンストラクタで指定した場合、指定できない |
---|
| 91 | + | |
---|
| 92 | + | ** quantifier [#wh64NXe] |
---|
| 93 | + | :引数|string|Expression $quantifier DISTINCT|ALL |
---|
| 94 | + | |
---|
| 95 | + | DISTINCT属性を設定するか。 |
---|
| 96 | + | |
---|
| 97 | + | ** columns [#StzSgn0] |
---|
| 98 | + | :引数|array $columns |
---|
| 99 | + | |
---|
| 100 | + | selectするカラム名を指定する |
---|
| 101 | + | 連想配列の場合、''key値がエイリアス名''になる。 |
---|
| 102 | + | #sh(php){$select->columns(array("*"));} |
---|
| 103 | + | `test`.* |
---|
| 104 | + | #sh(php){$select->columns(array("id", "name", "value"));} |
---|
| 105 | + | `test`.`id` AS `id`, `test`.`name` AS `name`, `test`.`value` AS `value` |
---|
| 106 | + | #sh(php){$select->columns(array("id"=>"rev_id", "name"=>"rev_name", "value"=>"rev_value"));} |
---|
| 107 | + | `test`.`rev_id` AS `id`, `test`.`rev_name` AS `name`, `test`.`rev_value` AS `value` |
---|
| 108 | + | |
---|
| 109 | + | ** join [#slAKJ1d] |
---|
| 110 | + | :引数|string|array $name |
---|
| 111 | + | string $on |
---|
| 112 | + | string|array $columns |
---|
| 113 | + | string $type JOIN_*の中から一つ |
---|
| 114 | + | |
---|
| 115 | + | 結合設定 |
---|
| 116 | + | JOIN_INNER、JOIN_OUTER、JOIN_LEFT、JOIN_RIGHTの4種類が指定可能 |
---|
| 117 | + | #sh(php){$select->join("test2", "test.id = test2.id", Zend\Db\Sql\Select::SQL_STAR, Zend\Db\Sql\Select::JOIN_LEFT);} |
---|
| 118 | + | `test2`.* FROM `test` LEFT JOIN `test2` ON `test`.`id` = `test2`.`id` |
---|
| 119 | + | #sh(php){$select->join("test2", "test.id = test2.id", array("id", "name", "age"), Zend\Db\Sql\Select::JOIN_LEFT);} |
---|
| 120 | + | `test2`.`id` AS `id`, `test2`.`name` AS `name`, `test2`.`age` AS `age` FROM `test` LEFT JOIN `test2` ON `test`.`id` = `test2`.`id` |
---|
| 121 | + | |
---|
| 122 | + | ** where [#LrEKQK5] |
---|
| 123 | + | :引数|Where|\Closure|string|array|Predicate\PredicateInterface $predicate |
---|
| 124 | + | string $combination Predicate\PredicateSetで定義されている OP_* の中から一つ |
---|
| 125 | + | |
---|
| 126 | + | Where句を設定 |
---|
| 127 | + | #sh(php){$select->where(array("id"=>1, "name"=>"yamada"));} |
---|
| 128 | + | WHERE `id` = '1' AND `name` = 'yamada' |
---|
| 129 | + | #sh(php){$select->where(array("id"=>1, "name"=>"yamada"), Zend\Db\Sql\Predicate\PredicateSet::OP_OR);} |
---|
| 130 | + | WHERE `id` = '1' OR `name` = 'yamada' |
---|
| 131 | + | Predicate\PredicateInterface |
---|
| 132 | + | #sh(php){{ |
---|
| 133 | + | $nest = $select->where->nest(); |
---|
| 134 | + | $nest->equalTo("name", "yamada"); |
---|
| 135 | + | $nest->OR->equalTo("age", "20"); |
---|
| 136 | + | $nest->unnest(); |
---|
| 137 | + | }} |
---|
| 138 | + | WHERE (`name` = 'yamada' OR `age` = '20') |
---|
| 139 | + | #sh(php){{ |
---|
| 140 | + | $nest = $select->where->nest(); |
---|
| 141 | + | $nest2_1 = $nest->nest(); |
---|
| 142 | + | $nest2_1->equalTo("name", "yamada"); |
---|
| 143 | + | $nest2_1->OR->equalTo("name", "tanaka"); |
---|
| 144 | + | $nest2_1->unnest(); |
---|
| 145 | + | $nest2_2 = $nest->AND->nest(); |
---|
| 146 | + | $nest2_2->equalTo("age", "10"); |
---|
| 147 | + | $nest2_2->OR->equalTo("age", "20"); |
---|
| 148 | + | $nest2_2->unnest(); |
---|
| 149 | + | $nest->unnest(); |
---|
| 150 | + | }} |
---|
| 151 | + | WHERE ((`name` = 'yamada' OR `name` = 'tanaka') AND (`age` = '10' OR `age` = '20')) |
---|
| 152 | + | #sh(php){$select->where->NEST->equalTo("name", "yamada")->OR->equalTo("age", "20")->UNNEST;} |
---|
| 153 | + | WHERE (`name` = 'yamada' OR `age` = '20') |
---|
| 154 | + | #sh(php){{ |
---|
| 155 | + | $select->where->NEST |
---|
| 156 | + | ->NEST |
---|
| 157 | + | ->equalTo("name", "yamada") |
---|
| 158 | + | ->OR->equalTo("name", "tanaka") |
---|
| 159 | + | ->UNNEST |
---|
| 160 | + | ->AND->NEST |
---|
| 161 | + | ->equalTo("age", "10") |
---|
| 162 | + | ->OR->equalTo("age", "20") |
---|
| 163 | + | ->UNNEST |
---|
| 164 | + | ->UNNEST; |
---|
| 165 | + | }} |
---|
| 166 | + | WHERE ((`name` = 'yamada' OR `name` = 'tanaka') AND (`age` = '10' OR `age` = '20')) |
---|
| 167 | + | ** group [#8OTtXtP] |
---|
| 168 | + | :|引数|string|array |
---|
| 169 | + | |
---|
| 170 | + | グループ設定 |
---|
| 171 | + | #sh(php){$select->group("name");} |
---|
| 172 | + | GROUP BY `name` |
---|
| 173 | + | |
---|
| 174 | + | ** having [#aDnoqCD] |
---|
| 175 | + | :引数|Where|\Closure|string|array $predicate |
---|
| 176 | + | string $combination One of the OP_* constants from Predicate\PredicateSet |
---|
| 177 | + | |
---|
| 178 | + | #sh(php){$select->having(array("age"=>10, "weight"=>20));} |
---|
| 179 | + | HAVING `age` = '10' AND `weight` = '20' |
---|
| 180 | + | |
---|
| 181 | + | ** order [#LBspsa8] |
---|
| 182 | + | :引数|string|array $order |
---|
| 183 | + | |
---|
| 184 | + | オーダー設定 |
---|
| 185 | + | #sh(php){$select->order("name DESC");} |
---|
| 186 | + | ORDER BY `name` DESC |
---|
| 187 | + | #sh(php){$select->order("name ASC");} |
---|
| 188 | + | ORDER BY `name` ASC |
---|
| 189 | + | |
---|
| 190 | + | ** limit [#jolzJvg] |
---|
| 191 | + | :引数|int $limit |
---|
| 192 | + | |
---|
| 193 | + | Limit設定 |
---|
| 194 | + | #sh(php){$select->limit(1);} |
---|
| 195 | + | LIMIT 1 |
---|
| 196 | + | |
---|
| 197 | + | ** offset [#zD1URqW] |
---|
| 198 | + | :引数|int $offset |
---|
| 199 | + | |
---|
| 200 | + | Offset設定 |
---|
| 201 | + | #sh(php){$select->offset(3);} |
---|
| 202 | + | OFFSET 3 |
---|
| 203 | + | ** combine [#OlWRQfW] |
---|
| 204 | + | :引数|Select $select |
---|
| 205 | + | string $type |
---|
| 206 | + | string $modifier |
---|
| 207 | + | |
---|
| 208 | + | * Delete [#FY0yK4i] |
---|
| 209 | + | Zend\Db\Sql\Sqlクラスのdeleteメソッドから呼び出される。 |
---|
| 210 | + | **基本的な利用方法 [#lBWhe9H] |
---|
| 211 | + | ** コンストラクタ [#AiHrSi5] |
---|
| 212 | + | :引数|null|string|TableIdentifier $table |
---|
| 213 | + | |
---|
| 214 | + | テーブル名を指定する、fromメソッドが優先される |
---|
| 215 | + | |
---|
| 216 | + | ** from [#8EVuCLJ] |
---|
| 217 | + | :引数|string|TableIdentifier $table |
---|
| 218 | + | |
---|
| 219 | + | テーブル名を指定する |
---|
| 220 | + | |
---|
| 221 | + | **where [#F1VAe0W] |
---|
| 222 | + | [[selectメソッドのwhere>Zend/Db/Sql#LrEKQK5]]を参照のこと。 |
---|
| 223 | + | |
---|
| 224 | + | * Update [#wj5CLPO] |
---|
| 225 | + | Zend\Db\Sql\Sqlクラスのupdateメソッドから呼び出される。 |
---|
| 226 | + | **基本的な利用方法 [#nmLH3Nz] |
---|
| 227 | + | ** コンストラクタ [#IEdT5sD] |
---|
| 228 | + | :引数|null|string|TableIdentifier $table |
---|
| 229 | + | |
---|
| 230 | + | テーブル名を指定 |
---|
| 231 | + | |
---|
| 232 | + | **table [#2Kz2hCu] |
---|
| 233 | + | :引数|string|TableIdentifier $table |
---|
| 234 | + | |
---|
| 235 | + | テーブル名を指定 |
---|
| 236 | + | |
---|
| 237 | + | **set [#EgjEkNU] |
---|
| 238 | + | :引数|array $values 連想配列 |
---|
| 239 | + | string $flag VALUES_*の値 |
---|
| 240 | + | |
---|
| 241 | + | **where [#ufoF0Ek] |
---|
| 242 | + | [[selectメソッドのwhere>Zend/Db/Sql#LrEKQK5]]を参照のこと。 |
---|