PDO connect, select & insert blank template

Posted 2 years ago

		$host     = "localhost";
		$user     = 'user';
		$password = 'pass';
		$dbname   = 'dbname';	

		try {
	    $conn = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $user, $password);
	    // set the PDO error mode to exception
	    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	    return $conn;
    }	catch(PDOException $e) {
	    exit("Connection failed: " . $e->getMessage());
	  }



		$stmt 	= $this->db->prepare("SELECT * FROM `users` WHERE `user_id` = :id ORDER BY `user_id` DESC LIMIT 1");
		$stmt->bindValue(':id', $id);
		$stmt->execute();
		$stmt->rowCount();

		$stmt->fetch(PDO::FETCH_OBJ);
		$stmt->fetch(PDO::FETCH_ASSOC);
		$stmt->fetch(PDO::FETCH_NUM);