SELECT * FROM accounts WHERE type IN (1, 2)
UNION ALL
SELECT * FROM accounts WHERE type IN (3, 4)
$sql = [];
$params = [];
$PDO; // Создаете PDO объект
for($i = 0, $max = 10; $i < $max; $i++) {
$sql[] = "SELECT * FROM accounts WHERE type IN (?, ?)\r\n";
$params[] = 0; // число 1
$params[] = 1; // число 2
}
$query = implode("UNION ALL\r\n", $sql);
$sth = $PDO->prepare($query);
foreach($params as $key => $value) {
$sth->bindValue($key, $value);
}
$sth->execute();
$sth->fetchAll(PDO::FETCH_ASSOC);
class MyBigClass
{
var $allocatedSize;
var $allMyOtherStuff;
}
function AllocateMyBigClass()
{
$before = memory_get_usage();
$ret = new MyBigClass;
$after = memory_get_usage();
$ret->allocatedSize = ($after - $before);
return $ret;
}
/**
* Добавляем производителя
*
* @param string|null $result
*/
public function addProducer($result = null)
{
// проверка на авторизацию
$this->logged();
if (isset($_POST['submit'])) {
$Producer = new Producer(new DataBase());
$res = $Producer->addProducer(1, $_POST['producer']);
$res = ($res === true) ? 'success' : 'error';
header('Location: ' . _HTTP_SERVER . 'admin/add-producer/' . $res);
exit;
}
$data = [];
$data['result'] = $result;
$this->renderAdminPage('add_producer', $data);
}
// ------- AJAX -------
/**
* Удаление производителя
* @param int|null $producerId
*/
public function delProducer($producerId = null)
{
// проверка на авторизацию
$this->logged();
if (isset($_POST['producerId'])) {
$Producer = new Producer(new DataBase());
echo json_encode(['result' => $Producer->delProducer($_POST['producerId'])]);
}
}