Commit c9b6198f authored by Alexander Butenko's avatar Alexander Butenko

Revert "ups"

This reverts commit a6f3e051.
parent a6f3e051
......@@ -215,48 +215,6 @@ class MysqliDb
return $this->_dynamicBindResults($stmt);
}
/**
* Pass in an array of subqueries for union query construction.
*
* @param array $objects Contains a user-provided array of subqueries
* @param $type 'ALL', 'DISTINCT', null.
*
* @return array Contains the returned rows from the query.
*/
public function union ($objects, $type = null)
{
$allowedTypes = array('ALL', 'DISTINCT');
$type = strtoupper (trim ($type));
if ($type && !in_array ($type, $allowedTypes))
die ('Wrong UNION type: '.$type);
if (!is_array ($objects))
return;
$this->_query = "";
$i = 0;
foreach ($objects as $obj) {
if (!is_object ($obj))
continue;
if ($i++ != 0)
$this->_query .= " UNION {$type} ";
$subQuery = $obj->getSubQuery();
$this->_query .= "(" . $subQuery['query'] . ")";
foreach ($subQuery['params'] as $v)
$this->_bindParam ($v);
}
$stmt = $this->_buildQuery (null);
$stmt->execute();
$this->_stmtError = $stmt->error;
$this->reset();
return $this->_dynamicBindResults($stmt);
}
/**
*
* @param string $query Contains a user-provided select query.
......
......@@ -260,21 +260,6 @@ $data = Array (
$id = $db->insert ("products", $data);
// Gives INSERT INTO PRODUCTS (productName, userId, lastUpdated) values ("test product", (SELECT name FROM users WHERE id = 6), NOW());
```
UNION queries
```php
$common = $db->subQuery();
$common->where ("agentId", 10);
$customers = $common->copy();
$customers->get ("customers");
$users = $common->copy();
$users->get ("users");
$db->orderBy ("lastModified");
$res = $db->union (Array ($customers, $users, $companies), "ALL");
GIVES (SELECT * FROM customers WHERE agentId = 10 ) UNION ALL (SELECT * FROM users WHERE agentId = 10 ) ORDER BY lastModified DESC
```
### Helper commands
Reconnect in case mysql connection died
```php
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment