PHP Date and Time

profileanisa11
blog_by_date_sources-1.zip

blog_db_interface.php

<?php include_once('blog_exceptions.php'); class class_DB_Interface { /******************************************************** * * Data definitions. Per instantiation * * Implementatiion details ae hidden from the user * This is the definition of encapsulation * ********************************************************/ private $referer; function __construct() { $referer = $_SERVER['HTTP_REFERER']; echo '<p><a href="'. $referer .'" title="Return to the previous page">&laquo; Go back</a></p>'; } function __destruct(){ } public function blogPostsSummary() { $db = @new mysqli('localhost', 'blogdb_user', 'blogdb_userPW', 'blogdbx'); if (mysqli_connect_errno()) { throw new MySQLI_Exception(" Unable to connect to MYSQL server ", mysqli_connect_errno()); } // Create a join to pull information from the database $query = "SELECT blogdb.users.Blogger_Name,". " blogdb.post.Post_Summary". " from blogdb.users". " inner join blogdb.post". " on blogdb.users.idUser = blogdb.post.User_idUser1"; $stmt = $db->prepare($query); $stmt->execute(); $stmt->bind_result($bname, $summary); //echo "<br/>Blogs Summary</p>"; while($stmt->fetch()) { echo $bname." ".$summary."</p>"; } $stmt->free_result(); $db->close(); } public function allBloggers() { $db = @new mysqli('localhost', 'blogdb_user', 'blogdb_userPW', 'blogdb'); if (mysqli_connect_errno()) { throw new MySQLI_Exception(); } // Create a simple query to pull all blogger names from the DB return; } public function blogPostsByBlogger($bname) { $db = @new mysqli('localhost', 'blogdb_user', 'blogdb_userPW', 'blogdb'); if (mysqli_connect_errno()) { throw new MySQLI_Exception(); } $query = "SELECT blogdb.users.Blogger_Name,". " blogdb.post.Post_Summary". " from blogdb.users". " inner join blogdb.post". " on blogdb.users.idUser = blogdb.post.User_idUser1". " and blogdb.users.Blogger_Name = ?"; $stmt = $db->prepare($query); $stmt->bind_param('s', $bname); $stmt->execute(); $stmt->bind_result($blogger_name, $bsummary); // Pull the result into the PHP runtime. copies result data allowing memory to be freed in the // MYSQL runtime environment $stmt->store_result(); // Note: $STMT::num_rows is zero without first calling this API $numBlogs = 0; echo "<br />Blogs for : ".$bname."</p>"; while($stmt->fetch()) { echo $bsummary."</p>"; $numBlogs++; } $stmt->free_result(); $db->close(); } public function insertBlog($bloggerName, $blogSummary, $blogContent) { $db = @new mysqli('localhost', 'blogdb_user', 'blogdb_userPW', 'blogdb'); if (mysqli_connect_errno()) { throw new MySQLI_Exception(); } // Create a query to get the user ID // Now add a row to the post table; have to use the ID obtained from the previous query } public function searchByDate($dt_stamp) { $db = @new mysqli('localhost', 'blogdb_user', 'blogdb_userPW', 'blogdb'); if (mysqli_connect_errno()) { throw new MySQLI_Exception(); } // Create a query to search for blogs that were created before the date passed in by $dt_stamp } }; ?>

blog_exceptions.php

<?php class MySQLI_Exception extends Exception { function __toString() { return $this->getCode(). ": ". $this->getMessage(). "<br />". " in ". $this->getFile(). " on line ". $this->getLine(). "<br />"; } } ?>

blog_user.php

searchByDate($datetime); } else { // error handling } } catch( Exception $ge) { echo $ge; } ?>

user.html

Display Bloggers and Blogs

Search for Blogs

Search for Blogs created after this date: