function __construct($where, $order = "") { $this->titles = array(); $this->posters = array(); $this->comments = array(); $this->ids = array(); $this->host = 'localhost'; $this->user = '******'; $this->password = ''; $this->database = 'forumDB'; $order = "id {$order}"; $db = new DbAccess($this->host, $this->user, $this->password, $this->database); $result = $db->selectDB("threads", $where, '', $order); if ($result) { $rows = $result->num_rows; for ($i = 0; $i < $rows; $i++) { $result->data_seek($i); $row = $result->fetch_array(MYSQLI_ASSOC); array_push($this->titles, $row['title']); array_push($this->posters, $row['poster']); array_push($this->comments, $row['comment']); array_push($this->ids, $row['id']); } } }
/** * * @param int $idx * @param array $configArray * @throws AiryException */ public static function assignDbAccess($idx, $configArray) { if (!isset($configArray['dbtype'])) { throw new AiryException("no dbtype setting in the config.ini"); } //pdo is the default connection type $connectionType = "pdo"; if (isset($configArray['connection_type'])) { $connectionType = $configArray['connection_type']; } else { if (strtolower($configArray['dbtype']) == "mongodb") { $connectionType = "mongodb"; } } if (strtolower($connectionType) == "pdo") { $access = new PdoAccess(); } else { if (strtolower($connectionType) == "mongodb") { $access = new MongoDbAccess(); } else { $access = new DbAccess(); } } //set and put into array $access->config($idx); self::$dbAccessElements[$idx] = $access; }
function add_user_to_db() { $this->hashPass(); $db = new DbAccess(); $pdo = $db->getPDO(); $stmt = $pdo->prepare("INSERT INTO credentials (username, password, salt_hex, hashed_pass, date_of_reg) VALUES (:username, :password, :salt_hex, :hashed_pass, NOW())"); try { $stmt->execute(array('username' => $this->username, 'password' => $this->password, 'salt_hex' => $this->salt_hex, 'hashed_pass' => $this->hashed_pass)); echo "User: "******" has been inserted into DB." . "<br />"; } catch (Exception $e) { echo 'Message: ' . $e->getMessage() . '<br />'; } }
function showImage($image_id) { $db = new DbAccess(); $pdo = $db->getPDO(); $stmt = $pdo->prepare("SELECT image_filename FROM image_data WHERE image_id = :image_id"); try { $stmt->execute(array('image_id' => $image_id)); $row = $stmt->fetch(); return $row['image_filename']; } catch (Exception $e) { echo 'Message: ' . $e->getMessage() . '<br />'; } }
$user_id = $_SESSION['user_id']; echo "Welcome " . $username . " ! This is your page!" . "<br />"; echo "<img src='" . showUserImages($user_id) . "'></img>"; echo ' <a href="logout.php">Logout</a>' . "<br />"; } if (isset($_POST['submit'])) { $image_description = trim($_POST['image_description']); $screenshotFilename = trim($_FILES['screenshot']['name']); if (!empty($screenshotFilename)) { $screenshot = time() . $_FILES['screenshot']['name']; $screenshotType = $_FILES['screenshot']['type']; $screenshotSize = $_FILES['screenshot']['size']; if ($screenshotType == 'image/jpeg' || $screenshotType == 'image/pjpeg' || $screenshotType == 'image/gif' || $screenshotType == 'image/png' && $screenshotSize > 0) { $target = './images/' . $screenshot; move_uploaded_file($_FILES['screenshot']['tmp_name'], $target); $db = new DbAccess(); $pdo = $db->getPDO(); $stmt = $pdo->prepare("INSERT INTO image_data (user_id, image_description, image_filename, image_post_date) VALUES (:user_id, :image_description, :image_filename, NOW())"); try { $stmt->execute(array('user_id' => $user_id, 'image_description' => $image_description, 'image_filename' => $target)); echo "Image has been inserted into DB." . "<br />"; } catch (Exception $e) { echo 'Message: ' . $e->getMessage() . '<br />'; } } } } ?> <p>Add tr profile.</p>