function userPostCount($user_id) { $db = new Database(); $db->query("SELECT * FROM topics \n\t\t\t\t\t WHERE user_id=:user_id"); $db->bind('user_id', $user_id); $db->resultSet(); $topic_count = $db->rowCount(); $db->query("SELECT * FROM replies\n\t\t\t\t WHERE user_id=:user_id"); $db->bind('user_id', $user_id); $db->resultSet(); $reply_count = $db->rowCount(); return $topic_count + $reply_count; }
function userPostCount($user_id) { $db = new Database(); //topic count $db->query("SELECT * FROM topics\n\t\t\t\tWHERE user_id = :user_id\n\t\t\t\t"); $db->bind(":user_id", $user_id); $rows = $db->resultset(); $topic_count = $db->rowCount(); //reply count $db->query("SELECT * FROM replies\n\t\t\t\tWHERE user_id = :user_id\n\t\t\t\t"); $db->bind(":user_id", $user_id); $rows = $db->resultset(); $reply_count = $db->rowCount(); return $topic_count + $reply_count; }
/** * User Login * * @param $username * @param $password * @return bool */ public function login($username, $password) { $this->db->query("SELECT * FROM users\n\t\t\t\tWHERE username = :username\n\t\t\t\tAND password = :password"); //Bind Values $this->db->bind(':username', $username); $this->db->bind(':password', $password); $row = $this->db->single(); //Check Rows if ($this->db->rowCount() > 0) { $this->setUserData($row); return true; } else { return false; } }
function commentsCount($post_id) { $db = new Database(); $db->query("SELECT * FROM comments WHERE post_id = :post_id"); $db->bind(':post_id', $post_id); $rows = $db->resultset(); return $db->rowCount(); }
function userPostCount($user_id) { $db = new Database(); $db->query('SELECT * FROM topics WHERE user_id = :user_id '); $db->bind(':user_id', $user_id); //Assign Rows $rows = $db->resultset(); //Get Count $topic_count = $db->rowCount(); $db->query('SELECT * FROM replies WHERE user_id = :user_id '); $db->bind(':user_id', $user_id); //Assign Rows $rows = $db->resultset(); //Get Count $reply_count = $db->rowCount(); return $topic_count + $reply_count; }
function topicCount($category_id) { if ($category_id == null) { $topicCount = new Topic(); return $topicCount->getTotalTopics(); } else { $db = new Database(); $db->query("SELECT * FROM topics WHERE category_id = :category_id"); $db->bind(':category_id', $category_id); $row = $db->resultset(); $count = $db->rowCount(); return $count; } }
/** * @covers DataBase::delete * @covers Database::select * @covers Database::selectOne */ public function testDelete() { $this->db->select('name', 'test'); $this->assertEquals(3, $this->db->rowCount()); $this->assertEquals(1, $this->db->delete('test', array('id' => 1))); $this->assertEmpty($this->db->selectOne('name', 'test', array('id' => 1))); $this->db->select('name', 'test'); $this->assertEquals(2, $this->db->rowCount()); $result = $this->db->select('*', 'test'); $this->assertEquals(0, $this->db->delete('test', array('id' => 0))); $this->assertFalse(LoggerApp::hasError(), LoggerApp::getLastError()); $this->assertEquals(0, $this->db->delete('testinvalid', array('xyz' => 1))); $this->assertTrue(LoggerApp::hasError(), 'Não gerou o erro esperado'); //Update without where $this->assertEquals(0, $this->db->delete('test', array())); }
public function getDetailsByUsername($username) { $database = new Database(); $database->query("SELECT * FROM engineers WHERE sAMAccountName = :username"); $database->bind(":username", $username); $row = $database->single(); // if no results return empty object if ($database->rowCount() == 0) { return null; } // else populate opbject with db results $userObject = new stdClass(); $userObject->sAMAccountName = $row['sAMAccountName']; $userObject->engineerLevel = $row['engineerLevel']; $userObject->idengineers = $row['idengineers']; $userObject->superuser = $row['superuser']; $userObject->helpdesk = $row['helpdesk']; $userObject->localHash = $row['localLoginHash']; return $userObject; }
public function doLogin($username, $password) { $db = new Database(); $db->query("SELECT id,username,email,avatar,about,last_activity,status FROM users WHERE username=:username AND password=:pass"); $db->bind(":username", $username); $db->bind(":pass", $password); $user = $db->single(); if ($db->rowCount() > 0) { if ($user->status == 1) { $this->user = $user; if (!$this->setUserSession()) { redirect("index.php", "values not set", "error"); } } else { redirect("index.php", "Please confirm your mail.", "warning"); } return true; } else { return false; } }
/** * Get Total Number Of Comments * * @return mixed */ public function getTotalComments() { $this->db->query("SELECT * FROM comments"); $rows = $this->db->resultset(); return $this->db->rowCount(); }
} // get security object $security = new Security(); // no article is selected if (!isset($_GET['id'])) { header("Location: http://localhost/Appstrike/index.php"); die; } // get article $database = new Database(); if ($security->mode == 'high') { // do pdo preparation $database->query('SELECT * from Articles WHERE id=:id LIMIT 1'); $database->bind(':id', $_GET['id']); $database->execute(); if ($database->rowCount() > 0) { $article = $database->single(); } else { // id not correct header("Location: http://localhost/Appstrike/index.php"); die; } } else { if ($security->mode == 'low') { // do query execution directly $id = $_GET['id']; $statement = $database->dbh->query("SELECT * from Articles WHERE id='{$id}'"); if (!$statement) { print_r($pdo->errorInfo()); die; }
$numErrorComplete += 1; } if ($day === "0" || $day == null || !isset($day)) { $errorMessage = $errorMessage . $signmark . " The day of Birth is missing.<br>"; $numErrorComplete += 1; } if ($gender === "0" || $gender == null || !isset($gender)) { $errorMessage = $errorMessage . $signmark . " The gender is missing.<br>"; $numErrorComplete += 1; } // Going to check if email and phone are unique in systems. $db = new Database(); $sql = "SELECT * FROM `customer` WHERE email = '{$email}' OR phone = '{$phone}'"; $db->query($sql); $db->execute(); if ($db->rowCount() > 0) { $errorMessage = $errorMessage . $signmark . " Email or Phone number is already existed.<br>"; $numErrorComplete += 1; } ?> <!DOCTYPE html> <html> <head> <title>Sign Up - WU XING</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <link rel="shortcut icon" href="img/headline.ico"> <link rel="stylesheet" href="css/demo.css">
<td><input type="text" name="camiao-escolha" placeholder="Insira aqui o número do camião" required /></td> </tr> <tr> <td><button type="submit" name="btn-normalizar-temperatura">Enviar</button></td> </tr> </table> </form> </div> <div id="lista-camioes"> <?php require_once '../class/database.class.php'; $database = new Database(); $database->query("SELECT utruck FROM ultimastemperaturas"); $result = $database->resultset(); $count = $database->rowCount(); if ($count > 0) { for ($i = 0; $i < $count; $i++) { echo "Camião número: " . $result[$i]["utruck"]; echo "<br />"; } } else { echo "Nenhum camião disponível."; } ?> </div> <div id="notification"></div> </div> </body> </html>
function checkIP($ip, $gt) { $database = new Database(); $sql = "SELECT * FROM LoginAttempts WHERE ip=:ip"; $database->query($sql); $database->bind(':ip', $ip); $row = $database->single(); $count = $database->rowCount(); //IP has less than 3 attempts if ($count < 4) { return true; //mas de 3 intentos } else { return false; } }
} ?> </li> <?php } } else { echo '<li><div style="font-weight:bold;text-align:center !important;">No new notifications</div> </li>'; } ?> </ul> </div> <?php } else { redirect("home.php"); } ?> </div> <div id="number"> <?php if (isLoggedIn()) { $u_id = $_SESSION['user_id']; $db = new Database(); $db->query("SELECT DISTINCT body,link,id FROM notifications WHERE (u_id=:u_id AND u_id!=from_id AND seen='0' AND hide='0') ORDER BY id DESC "); $db->bind("u_id", $u_id); $r = $db->resultset(); echo $db->rowCount(); } ?> </div>
<ul class="sub-menu"> <li <?php if (pagActual() == "galeria.php") { echo ' class="active"'; } ?> > <a href="galeria.php"> <i class="fa fa-list"></i> Listado</a> </li> <?php $database = new Database(); $sql = "SELECT * FROM galeria ORDER BY album_id ASC"; $database->query($sql); if ($database->rowCount() != 0) { $rows = $database->resultset(); foreach ($rows as &$row) { echo '<li '; if (pagActual() == "album_fotos.php" && intval($_GET['id']) == $row['album_id']) { echo ' class="active"'; } else { if (pagActual() == "foto_new.php" && intval($_GET['id']) == $row['album_id']) { echo ' class="active"'; } else { if (pagActual() == "foto_new_upload.php" && intval($_POST['id']) == $row['album_id']) { echo ' class="active"'; } } } echo '>
3) program generates a random reset key code 4) program sends email with a link to click on. the url contains the reset code 5) user clicks on the link, link opens a page verifying the that the reset code is correct 6) after verification, user can change password on that new page that opened. ***************************************************************************************************/ // user supplies the email needing password change. //database object is used to that the account is already registered (in the database) $db = new Database(); if (isset($_POST['pw-reset-submit']) && !fieldsEmpty($_POST)) { // if post, user has requested password change... $userEmail = $_POST['pw-reset-email']; // extract user email address $db->prepare("SELECT * FROM users WHERE email=?", [$userEmail]); // verify that the email address is in database $db->execute(); if ($db->rowCount() !== 0) { // if it's in the database... $resultSet = $db->fetchRow(); // store the row result $userName = $resultSet['firstName'] . ' ' . $resultSet['lastName']; // create an array: ['first name', 'last name'] $resetKey = createResetKey(); // call helper function to generate a reset key // create a URL link with the reset key as part of the URL // an email will be sent to the user with this link // user will click on this link to verify they are the owner of the email address. $clickStr = "http://176.32.230.8/pliustock.com/change&email=" . urlencode($userEmail) . "&reset-key=" . $resetKey; // store the generated key in the database. // later a check will be made between database key & the key in the URL clicked on by user // if they match then that confirms the user is the owner of the email $db->prepare("UPDATE users SET reset_key=? WHERE email=?", [$resetKey, $userEmail]);
$sql = "SELECT FName, LName, Age, Gender FROM mytable WHERE FName = :fname"; $database->query($sql); $database->bind(':fname', 'Jenny'); $row = $database->single(); echo "<pre>"; print_r($row); echo "</pre>"; //multiple $sql = "SELECT FName, LName, Age, Gender FROM mytable WHERE LName = :lname"; $database->query($sql); $database->bind(':lname', 'Smith'); $rows = $database->resultset(); echo "<pre>"; print_r($rows); echo "</pre>"; echo $database->rowCount(); //update $UserID = 14; $sql = "UPDATE mytable SET FName = :fname, LName = :lname WHERE ID = :Userid"; $database->query($sql); $database->bind(':Userid', $UserID); $database->bind(':fname', 'Maria'); $database->bind(':lname', 'de Azpeitia'); $database->execute(); $UserID = 14; $sql = "UPDATE mytable SET FName = :fname, LName = :lname, Age = :age, Gender = :gender WHERE ID = :Userid"; $database->query($sql); $database->bindArray(array(':Userid' => $UserID, ':fname' => 'Maria', ':lname' => 'de de Azpeitia', ':age' => 23, ':gender' => 'female')); $database->execute(); $database->query('SELECT * FROM mytable WHERE ID= :Userid'); $database->bind(':Userid', $UserID);
function notify_number() { $u_id = $_SESSION['user_id']; $db = new Database(); $db->query("SELECT DISTINCT body,link FROM notifications WHERE u_id=:u_id AND seen='0' AND hide='0' AND u_id!=from_id"); $db->bind("u_id", $u_id); $r = $db->resultset(); if ($db->rowCount()) { return $db->rowCount(); } }
if (!$mail->Send()) { $error = 'Mail error: ' . $mail->ErrorInfo; return false; } else { $error = 'Confirmation Mail sent to the the provided mail!'; return true; } } $user = new User(); $db = new Database(); if (isset($_POST['do_forgot'])) { if (!empty($_POST['f_email'])) { $db->query("SELECT * FROM users WHERE email=:email AND status='1'"); $db->bind("email", $_POST['f_email']); $result = $db->single(); if ($db->rowCount() == 1) { $pass = $result->password; $pass = substr($pass, 0, 6); if (smtpmailer($result->email, "*****@*****.**", "AKHIL REDDY@ BITS QUORA", "Password reset for your account", $result->avatar, $result->name, $result->username, $pass)) { $db->query("UPDATE users SET password=:pass WHERE email=:email"); $db->bind("pass", md5(md5($pass))); $db->bind("email", $result->email); $db->execute(); echo 'We have sent your accout details to your mail.'; } else { echo 'Please try after some time'; } } else { echo 'Please register this email first.'; } } else {
//quick/simple validation if (empty($_GET['email']) || empty($_GET['key'])) { $action['result'] = 'error'; $action['text'] = 'Error con las variables, regresa a tu email y da click de nuevo.'; } if ($action['result'] != 'error') { //cleanup the variables $email = $_GET['email']; $key = $_GET['key']; //check if the key is in the database $sql = "SELECT * FROM `forgot` WHERE `email`=:email AND `key2`=:key LIMIT 1"; $database->query($sql); $database->bind(':email', $email); $database->bind(':key', $key); $database->execute(); $check_key = $database->rowCount(); if ($check_key != 0) { //get the confirm info $confirm_info = $database->single(); //confirm the email and update the users database $seed = '0123456789abcdefghijklmnopqrstuvwxyz'; $hash = sha1(uniqid($seed . mt_rand(), true)); $hash = substr($hash, 0, 10); $pass = password_hash($hash, PASSWORD_DEFAULT); $sql = "UPDATE `users` SET `user_passwd`=:user_passwd WHERE `user_id`=:user_id LIMIT 1"; $database->query($sql); $database->bindArray(array(':user_id' => $confirm_info['userid'], ':user_passwd' => $pass)); if ($database->execute()) { $action['result'] = 'success'; $action['text'] = 'Restablecimiento correcto!'; $run = 1;