Guest User

Untitled

a guest
Mar 12th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Fatal error: Cannot declare class database, because the name is already in
  2. use
  3. in C:OSPaneldomainsphploglibrariesdatabase.php on line 2
  4.  
  5. <?php
  6. class database{
  7. public $host = db_host;
  8. public $username = db_user;
  9. public $password = db_pass;
  10. public $db_name = db_name;
  11.  
  12. public $link;
  13. public $error;
  14.  
  15. /*
  16. * Class Constructor
  17. */
  18. public function __construct(){
  19. //Call Connect Function
  20. $this->connect();
  21. }
  22.  
  23. /*
  24. * Connector
  25. */
  26. private function connect() {
  27. $this->link = new mysqli($this->host, $this->username, $this->password,
  28. $this->db_name);
  29.  
  30. if(!$this->link) {
  31. $this->error = "Connection Failed: ".$this->link->connect_error;
  32. return false;
  33. }
  34. }
  35.  
  36. /*
  37. * Select
  38. */
  39. public function select($query) {
  40. $result = $this->link->query($query) or die($this->link-
  41. >error.__LINE__);
  42. if($result->num_rows > 0){
  43. return $result;
  44. } else {
  45. return false;
  46. }
  47. }
  48.  
  49. /*
  50. * Insert
  51. */
  52. public function insert($query) {
  53. $insert_row = $this->link->query($query) or die($this->link-
  54. >error.__LINE__);
  55.  
  56. //Validate Insert
  57. if($insert_row) {
  58. header("Location: index.php?msq=".urlencode('Record insert'));
  59. exit();
  60. }
  61. }
  62.  
  63. /*
  64. * Update
  65. */
  66. public function update($query) {
  67. $update_row = $this->link->query($query) or die($this->link-
  68. >error.__LINE__);
  69.  
  70. //Validate update
  71. if($update_row) {
  72. header("Location: index.php?msq=".urlencode('Record update'));
  73. }
  74. }
  75. }
  76. ?>
  77.  
  78. <?php include 'includes/header.php'; ?>
  79. <?php
  80. $id = $_GET['id'];
  81.  
  82. //Create DB Object
  83. $db = new database();
  84.  
  85. //Create Query
  86. $query = "SELECT * FROM posts WHERE id = ".$id;
  87. //Run Query
  88. $post = $db->select($query)->fetch_assoc();
  89.  
  90. //Create Query
  91. $query = "SELECT * FROM categories";
  92. //Run Query
  93. $categories = $db->select($query);
  94.  
  95. ?>
  96. <?php include 'includes/header.php'; ?>
  97. <div class="blog-post">
  98. <h2 class="blog-post-title"><?php echo $post['title']; ?></h2>
  99. <p class="blog-post-meta"><?php echo formatDate($post['date']); ?>
  100. by <?php echo $post['author']; ?></p>
  101. <?php echo shortenText($post['body']); ?>
  102. <a class="readmore" href="post.php?id=<?php echo
  103. urlencode($post['id']); ?>">Read more</a>
  104. </div><!-- /.blog-post -->
  105. <?php include 'includes/footer.php'; ?>
Add Comment
Please, Sign In to add comment