Rev 32 | Rev 34 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 32 | Rev 33 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | require_once __DIR__ . '/../global.inc'; |
3 | require_once __DIR__ . '/../global.inc'; |
4 | - | ||
5 | require_once __DIR__ . '/../AbstractModel.php'; |
4 | require_once __DIR__ . '/../AbstractModel.php'; |
6 | 5 | ||
7 | /**
|
6 | /**
|
8 | * Generic database model class using PDO (PHP Data Objects)
|
7 | * Generic database model class using PDO (PHP Data Objects)
|
9 | *
|
8 | *
|
Line 272... | Line 271... | ||
272 | $value = $value[key($value)]; |
271 | $value = $value[key($value)]; |
273 | }
|
272 | }
|
274 | 273 | ||
275 | if (is_array($value)) |
274 | if (is_array($value)) |
276 | {
|
275 | {
|
277 | $placeholder = '(' . implode(',', self::_expand($value, $column)) . ')'; |
276 | $placeholder = '(' . implode(', ', self::_expand($value, $column)) . ')'; |
278 | }
|
277 | }
|
279 | 278 | ||
280 | $result[] = $this->_leftQuote . $column . $this->_rightQuote . "{$op}{$placeholder}{$suffix}"; |
279 | $result[] = $this->_leftQuote . $column . $this->_rightQuote . "{$op}{$placeholder}{$suffix}"; |
281 | }
|
280 | }
|
282 | 281 | ||
Line 351... | Line 350... | ||
351 | if ($this->_isAssociativeArray($columns)) |
350 | if ($this->_isAssociativeArray($columns)) |
352 | {
|
351 | {
|
353 | $columns = $this->_escapeAliasArray($columns); |
352 | $columns = $this->_escapeAliasArray($columns); |
354 | }
|
353 | }
|
355 | 354 | ||
356 | $columns = implode(',', $columns); |
355 | $columns = implode(', ', $columns); |
357 | }
|
356 | }
|
358 | 357 | ||
359 | if (is_array($tables)) |
358 | if (is_array($tables)) |
360 | {
|
359 | {
|
361 | if ($this->_isAssociativeArray($columns)) |
360 | if ($this->_isAssociativeArray($columns)) |
362 | {
|
361 | {
|
363 | $columns = $this->_escapeAliasArray($columns); |
362 | $columns = $this->_escapeAliasArray($columns); |
364 | }
|
363 | }
|
365 | 364 | ||
366 | $tables = implode(',', $tables); |
365 | $tables = implode(', ', $tables); |
367 | }
|
366 | }
|
368 | 367 | ||
369 | $query = "SELECT {$columns} FROM {$tables}" . $this->_where($where); |
368 | $query = "SELECT {$columns} FROM {$tables}" . $this->_where($where); |
370 | 369 | ||
371 | if (!is_null($order)) |
370 | if (!is_null($order)) |
372 | {
|
371 | {
|
373 | if (is_array($order)) |
372 | if (is_array($order)) |
374 | {
|
373 | {
|
375 | $order = 'ORDER BY ' . implode(',', $order); |
374 | $order = 'ORDER BY ' . implode(', ', $order); |
376 | }
|
375 | }
|
377 | 376 | ||
378 | $query .= " $order"; |
377 | $query .= " $order"; |
379 | }
|
378 | }
|
380 | 379 | ||
Line 484... | Line 483... | ||
484 | throw new InvalidArgumentException('No table specified'); |
483 | throw new InvalidArgumentException('No table specified'); |
485 | }
|
484 | }
|
486 | 485 | ||
487 | if (is_array($tables)) |
486 | if (is_array($tables)) |
488 | {
|
487 | {
|
489 | $tables = implode(',', $tables); |
488 | $tables = implode(', ', $tables); |
490 | }
|
489 | }
|
491 | 490 | ||
492 | if (!$updates) |
491 | if (!$updates) |
493 | {
|
492 | {
|
494 | throw new InvalidArgumentException('No values specified'); |
493 | throw new InvalidArgumentException('No values specified'); |
Line 502... | Line 501... | ||
502 | {
|
501 | {
|
503 | $params[":{$key}"] = $condition; |
502 | $params[":{$key}"] = $condition; |
504 | }
|
503 | }
|
505 | }
|
504 | }
|
506 | 505 | ||
507 | $updates = implode(',', $this->_escapeValueArray($updates)); |
506 | $updates = implode(', ', $this->_escapeValueArray($updates)); |
508 | 507 | ||
509 | /* TODO: Should escape table names with escapeName(), but what about aliases? */
|
508 | /* TODO: Should escape table names with escapeName(), but what about aliases? */
|
510 | $query = "UPDATE {$tables} SET {$updates}" . $this->_where($where, '2'); |
509 | $query = "UPDATE {$tables} SET {$updates}" . $this->_where($where, '2'); |
511 | 510 | ||
512 | $stmt = $this->prepare($query); |
511 | $stmt = $this->prepare($query); |
Line 592... | Line 591... | ||
592 | {
|
591 | {
|
593 | if ($cols != null) |
592 | if ($cols != null) |
594 | {
|
593 | {
|
595 | $cols = ' (' |
594 | $cols = ' (' |
596 | . (is_array($cols) |
595 | . (is_array($cols) |
597 | ? implode(',', array_map(create_function('$s', 'return "`$s`";'), $cols)) |
596 | ? implode(', ', array_map(array($this, 'escapeName'), $cols)) |
598 | : $cols) . ')'; |
597 | : $cols) . ')'; |
599 | }
|
598 | }
|
600 | else
|
599 | else
|
601 | {
|
600 | {
|
602 | $cols = ''; |
601 | $cols = ''; |
Line 737... | Line 736... | ||
737 | throw new InvalidArgumentException('No table specified'); |
736 | throw new InvalidArgumentException('No table specified'); |
738 | }
|
737 | }
|
739 | 738 | ||
740 | if (is_array($tables)) |
739 | if (is_array($tables)) |
741 | {
|
740 | {
|
742 | $tables = implode(',', $tables); |
741 | $tables = implode(', ', $tables); |
743 | }
|
742 | }
|
744 | 743 | ||
745 | $params = array(); |
744 | $params = array(); |
746 | 745 | ||
747 | $query = "DELETE FROM {$tables}" . $this->_where($where); |
746 | $query = "DELETE FROM {$tables}" . $this->_where($where); |