Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fatal error: Cannot declare class database, because the name is already in
- use
- in C:OSPaneldomainsphploglibrariesdatabase.php on line 2
- <?php
- class database{
- public $host = db_host;
- public $username = db_user;
- public $password = db_pass;
- public $db_name = db_name;
- public $link;
- public $error;
- /*
- * Class Constructor
- */
- public function __construct(){
- //Call Connect Function
- $this->connect();
- }
- /*
- * Connector
- */
- private function connect() {
- $this->link = new mysqli($this->host, $this->username, $this->password,
- $this->db_name);
- if(!$this->link) {
- $this->error = "Connection Failed: ".$this->link->connect_error;
- return false;
- }
- }
- /*
- * Select
- */
- public function select($query) {
- $result = $this->link->query($query) or die($this->link-
- >error.__LINE__);
- if($result->num_rows > 0){
- return $result;
- } else {
- return false;
- }
- }
- /*
- * Insert
- */
- public function insert($query) {
- $insert_row = $this->link->query($query) or die($this->link-
- >error.__LINE__);
- //Validate Insert
- if($insert_row) {
- header("Location: index.php?msq=".urlencode('Record insert'));
- exit();
- }
- }
- /*
- * Update
- */
- public function update($query) {
- $update_row = $this->link->query($query) or die($this->link-
- >error.__LINE__);
- //Validate update
- if($update_row) {
- header("Location: index.php?msq=".urlencode('Record update'));
- }
- }
- }
- ?>
- <?php include 'includes/header.php'; ?>
- <?php
- $id = $_GET['id'];
- //Create DB Object
- $db = new database();
- //Create Query
- $query = "SELECT * FROM posts WHERE id = ".$id;
- //Run Query
- $post = $db->select($query)->fetch_assoc();
- //Create Query
- $query = "SELECT * FROM categories";
- //Run Query
- $categories = $db->select($query);
- ?>
- <?php include 'includes/header.php'; ?>
- <div class="blog-post">
- <h2 class="blog-post-title"><?php echo $post['title']; ?></h2>
- <p class="blog-post-meta"><?php echo formatDate($post['date']); ?>
- by <?php echo $post['author']; ?></p>
- <?php echo shortenText($post['body']); ?>
- <a class="readmore" href="post.php?id=<?php echo
- urlencode($post['id']); ?>">Read more</a>
- </div><!-- /.blog-post -->
- <?php include 'includes/footer.php'; ?>
- <?php include 'includes/header.php'; ?>
Add Comment
Please, Sign In to add comment