Social Networking Site Project Setup
Submitted by GeePee on Friday, April 17, 2015 - 23:48.
In this tutorial, I will show you how to set up our project before we start developing a several web pages. First lets create a folder name “philsocial” inside our web server. Since we will be using a Twitter Bootstrap framework, and if you don’t have a copy of this, you can download it here. After downloading, you need to extract it and copy the following folder such as assets, css, fonts and js. Then paste it inside “philsocial” folder, and add three new folder such as “img” where we’re going to store our images to be used later on, the another folder and name it as “uploads”. This folder will be used as a storage area for our upload files and documents. And finally the “includes” folder that will hold our different classes and libraries.
Here's the folder structure:
philsocial/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ ├── bootstrap-theme.css
│ ├── bootstrap-theme.min.css
├── js/
│ ├── bootstrap.js
│ ├── bootstrap.min.js
└── fonts/
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
└── glyphicons-halflings-regular.woff
|--- assets/
| |--css
| | |--pygments-manni.css
| | |--docs.css
| |--js
| | |--application.js
| | |--customizer.js
| | |--filesaver.js
| | |--holder.js
| | |--html5shiv.js
| | |--jquery.js
| | |--jszip.js
| | |--less.js
| | |--raw-files.js
| | |--respond.min.js
| | |--uglify.js
| |--ico
|--- uploads
|--- img
|--- includes
This time, we're going to create a new PHP file and name it as “config.php”, then save it inside includes folder. And add the following code:
Next,together with our “config.php file”, we’re going to create a PHP file that will hold and manage our Database objects, and this lets save this file as “database.php”, then add the following code:
And we need also to create another PHP file, then save it as “function.php” and add the following code:
This code is useful when we are cleaning some string or variable, redirecting to another page and automatic loading of different classes.
And finally, we will create another PHP file inside includes folder then, save it as “initialize.php” and add the following code:
This code will simply do the initialization of our different classes.
- <?php
- /**
- * Description: The main class for Database.
- * Author: Joken Villanueva
- * Date Created: October 27, 2013
- * Revised By:
- */
- //Database Constants
- ?>
- <?php
- /**
- * Description: The main class for Database.
- * Author: Joken Villanueva
- * Date Created: october27, 2013
- * Revised By:
- */
- require_once(LIB_PATH.DS."config.php");
- class Database {
- var $sql_string = '';
- var $error_no = 0;
- var $error_msg = '';
- private $conn;
- public $last_query;
- private $magic_quotes_active;
- private $real_escape_string_exists;
- function __construct() {
- $this->open_connection();
- }
- public function open_connection() {
- if(!$this->conn){
- echo "Problem in database connection! Contact administrator!";
- }else{
- if (!$db_select) {
- echo "Problem in selecting database! Contact administrator!";
- }
- }
- }
- function setQuery($sql='') {
- $this->sql_string=$sql;
- }
- function executeQuery() {
- $this->confirm_query($result);
- return $result;
- }
- private function confirm_query($result) {
- if(!$result){
- return false;
- }
- return $result;
- }
- function loadResultList( $key='' ) {
- $cur = $this->executeQuery();
- if ($key) {
- $array[$row->$key] = $row;
- } else {
- $array[] = $row;
- }
- }
- return $array;
- }
- function loadSingleResult() {
- $cur = $this->executeQuery();
- $data = $row;
- }
- return $data;
- }
- function getFieldsOnOneTable( $tbl_name ) {
- $this->setQuery("DESC ".$tbl_name);
- $rows = $this->loadResultList();
- $f[] = $rows[$x]->Field;
- }
- return $f;
- }
- public function fetch_array($result) {
- }
- //gets the number or rows
- public function num_rows($result_set) {
- }
- public function insert_id() {
- // get the last id inserted over the current db connection
- }
- public function affected_rows() {
- }
- public function escape_value( $value ) {
- if( $this->real_escape_string_exists ) { // PHP v4.3.0 or higher
- // undo any magic quote effects so mysql_real_escape_string can do the work
- } else { // before PHP v4.3.0
- // if magic quotes aren't already on then add slashes manually
- // if magic quotes are active, then the slashes already exist
- }
- return $value;
- }
- public function close_connection() {
- }
- }
- }
- $mydb = new Database();
- ?>
- <?php
- function strip_zeros_from_date($marked_string="") {
- //first remove the marked zeros
- return $cleaned_string;
- }
- function redirect_to($location = NULL) {
- if($location != NULL){
- exit;
- }
- }
- function output_message($message="") {
- return "<p class=\"message\">{$message}</p>";
- }else{
- return "";
- }
- }
- function __autoload($class_name) {
- $path = LIB_PATH.DS."{$class_name}.php";
- require_once($path);
- }else{
- }
- }
- ?>
- <?php
- /**
- * Description: This includes for basic and core configurations.
- * Author: Joken Villanueva
- * Date Created: october 27, 2013
- * Revised By:
- */
- //define the core paths
- //Define them as absolute peths to make sure that require_once works as expected
- //DIRECTORY_SEPARATOR is a PHP Pre-defined constants:
- //(\ for windows, / for Unix)
- // load config file first
- require_once(LIB_PATH.DS."config.php");
- //load basic functions next so that everything after can use them
- require_once(LIB_PATH.DS."functions.php");
- //later here where we are going to put our class session
- //Load Core objects
- require_once(LIB_PATH.DS."database.php");
- //load database-related classes
- ?>
Comments
Add new comment
- Add new comment
- 132 views