function queueGetter($conn, $condition) { try { if (empty($condition)) { $tsql = "SELECT [id],[Name],[Location] FROM dbo.Queue"; } else { $tsql = "SELECT [id],[Name],[Location] FROM dbo.Queue WHERE {$condition}"; } $conn = OpenConnection(); $getQueues = sqlsrv_query($conn, $tsql); if ($getQueues == FALSE) { echo "Error!!<br>"; die(print_r(sqlsrv_errors(), true)); } while ($row = sqlsrv_fetch_array($getQueues, SQLSRV_FETCH_ASSOC)) { $queue = new Queue($row['Name'], $row['Location']); $queue->setId($row['id']); $queues[] = $queue; } sqlsrv_free_stmt($getQueues); sqlsrv_close($conn); if (!empty($queues)) { return $queues; } else { return null; } } catch (Exception $e) { echo "Get Queue Error!"; } }
public function save(Queue $queue) { if ($queue->getId()) { $query = $this->dbAdapter->query('UPDATE `queues` SET `name` = :name WHERE `id = :id`'); $query->execute($queue->getArrayCopy()); } else { $query = $this->dbAdapter->query("INSERT INTO `queues` (`name`) VALUES (:name)"); $query->execute(['name' => $queue->getName()]); $queue->setId($this->dbAdapter->getDriver()->getLastGeneratedValue()); } return $queue; }