static function fetchAll() { DBConnection::connect(); $result = DBConnection::select('SELECT * FROM post'); $posts = []; if ($result) { foreach ($result as $post) { array_push($posts, new Post($post->id, $post->title, false)); } } return $posts; }
static function fetchAll() { DBConnection::connect(); $result = DBConnection::select('SELECT * FROM user'); $users = []; if ($result) { foreach ($result as $user) { array_push($users, new User($user->id, $user->pseudo, false)); } } return $users; }
public function getDataFromDBWithHosLog($HosLog) { $data = DBConnection::select("Select * from hospede WHERE HosLog='" . $HosLog . "'"); foreach ($data as $row) { $this->nome = $row['HosNom']; $this->login = $row['HosLog']; $this->senha = $row['HosPas']; $this->email = $row['HosEma']; $this->endereco = $row['HosEnd']; $this->cidade = $row['HosCid']; $this->pais = $row['HosPai']; $this->telefone = $row['HosTel']; $this->documento = $row['HosDoc']; } }
<?php /** * Created by PhpStorm. * User: GabrielAguiar * Date: 24/05/14 * Time: 14:51 */ $arriveDate = $_POST['postarrive']; $avaliable = false; $leaveDate = $_POST['postleave']; $number = $_POST['postnumber']; $data = DBConnection::select("SELECT * FROM reserva WHERE ResArr between '" . $arriveDate . "' and '" . $leaveDate . "'"); $i = 0; $newRes = new ReservaData(); $newRes->maxSingle -= $number; $newRes->maxCouple -= $number / 2; $newRes->maxLux -= $number; foreach ($data as $row) { if ($row['ResTip'] == 1) { $newRes->maxSingle--; } if ($row['ResTip'] == 2) { $newRes->maxCouple--; } if ($row['ResTip'] == 3) { $newRes->maxLux--; } } echo "<div style='color:white; width:91%; margin-top:10px; float:left;'class='gallery items-3'>"; if ($newRes->maxSingle > 0) {
<?php $login = $_POST['postlogin']; $pass = $_POST['postpass']; $tuts = 0; echo "<script>alert('HI')</script>"; $data = DBConnection::select("SELECT * FROM hospede"); foreach ($data as $row) { if ($row['HosLog'] == $login && $row['HosPas'] == $pass) { session_start(); $_SESSION['username'] = $row['HosLog']; $_SESSION['password'] = $row['HosPas']; $_SESSION['adm'] = $row['HosAdm']; $_SESSION['wrongLogin'] = false; $tuts = 1; } } if (!$tuts) { session_start(); $_SESSION['wrongLogin'] = true; }
<?php require_once '../model/DBConnection.php'; $db = new DBConnection(); /* * INSERT TEST. */ $lastInsertedId = $db->insert('truck', array('vehicle_capacity' => 0, 'brand' => 'Scania', 'age' => 4)); echo '<p> Last Inserted ID: ' . $lastInsertedId . '</p>'; /* * SELECT SINGLE TEST. */ echo '<p> All columns: '; var_dump($db->select('truck', '*', 'id', $lastInsertedId)); echo '</p>'; echo '<p> Some columns: '; var_dump($db->select('truck', array('brand', 'age'), 'id', $lastInsertedId)); echo '</p>'; /* * SELECT ALL TEST. */ $db->insert('truck', array('brand' => 'Mercedes', 'age' => 3)); echo '<p> All rows and columns: '; var_dump($db->select('truck', '*')); /* * UPDATE TEST. */ echo '<p> Before update: '; var_dump($db->select('truck', '*', 'id', $lastInsertedId)); echo '</p>'; $db->update('truck', array('vehicle_capacity' => 0, 'brand' => 'MAN', 'age' => 0), $lastInsertedId);
}); } </script> <?php $login = $_POST['postlogin']; $name = $_POST['postname']; $password = $_POST['postpass']; $email = $_POST['postemail']; $endereco = $_POST['postendereco']; $cidade = $_POST['postcidade']; $telefone = $_POST['posttelefone']; $documento = $_POST['postdocumento']; $pais = $_POST['postpais']; $loginStats = false; $emailStats = false; $data = DBConnection::select("Select * from hospede"); foreach ($data as $row) { if ($row['HonLog'] == $login) { $loginStats = true; } if ($row['HonEma'] == $email) { $loginStats = true; } } if ($loginStats) { echo "<script>signUp2()</script>"; } else { DBConnection::insert('Insert INTO hospede (HosNom,HosLog,HosPas,HosEma,HosEnd,HosCid,HosTel,HosDoc,HosPai) values("' . $name . '","' . $login . '","' . $password . '","' . $email . '","' . $endereco . '","' . $cidade . '","' . $telefone . '","' . $documento . '","' . $pais . '")'); }
/** * Count how many instances of this type reside in the database. If WHERE * condition is provided, only instances that correspond with the condition * will be counted. * @param string|array(string) $where Optional. * @param string|array(string) $value Optional. * @return int */ public function count($where = null, $value = null) { $db = new DBConnection(); $data = null; if ($where && $value) { $data = $db->select($this->convert_to_table_name($this->get_class_name()), 'COUNT(id)', $where, $value); } else { $data = $db->select($this->convert_to_table_name($this->get_class_name()), 'COUNT(id)'); } return intval($data[0]['COUNT(id)']); }