Advertisement
Guest User

Untitled

a guest
Apr 16th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. <!-- this is "inc/Database.php" -->
  2.  
  3. <?php
  4. class database{
  5.  
  6. public $server = "";
  7. public $user = "";
  8. protected $dbName;
  9.  
  10. protected $password = "";
  11.  
  12. public $error = array();
  13.  
  14. protected $conn;
  15.  
  16. public function __construct($server, $user, $password, $databaseName){
  17.  
  18. // check if the server is set
  19. if($server == "")
  20. {
  21. $this->error[] = "server is empty";
  22. }
  23.  
  24. // check if the password is set
  25. if($user == "")
  26. {
  27. $this->error[] = "user is empty";
  28. }
  29. // check if the server is set
  30. if($password == "")
  31. {
  32. $this->error[] = "password is empty";
  33. }
  34.  
  35. // check if the password is set
  36. if($databaseName == "")
  37. {
  38. $this->error[] = "databaseName is empty";
  39. }
  40.  
  41.  
  42. $this->server = $server;
  43. $this->user = $user;
  44. $this->password = $password;
  45. $this->dbName = $databaseName;
  46.  
  47.  
  48. }
  49.  
  50. function conn(){
  51. $conn = mysqli_connect($this->server, $this->user, $this->password, $this->dbName);// database connection
  52. return $conn;
  53. }
  54.  
  55. function select($colum = false, $table = false){
  56. $this->conn = conn();
  57. if(!$conn)
  58. {
  59. die("woops");
  60. }
  61. //maak verbinding
  62. //SELECT name FROM landen
  63. $sql = "SELECT ".$colum." FROM ". $table; //de SQL string
  64. $query = mysqli_query($conn, $sql); // Query uitvoeren
  65. mysqli_close($conn); // verinding sluiten
  66. return $query; // geef relultaat terug
  67.  
  68. }
  69.  
  70. function selectWhere($colum, $table, $where){
  71. $this->conn = conn();
  72. // SELECT name FROM landen WHERE landID=3
  73. $sql = "SELECT '".$colum."' FROM '".$table."' WHERE ".$where;
  74. $query = mysqli_query($conn, $sql);
  75. mysqli_close($conn);
  76. return $query;
  77. }
  78.  
  79. function insert($table, $colums,$values){
  80. $this->conn = conn();
  81. // INSERT INTO landen (name) VALUES (Duitsland)
  82. $sql = "INSERT INTO ".$table." (".$colums.") VALUES (".$values.")";
  83.  
  84. // INTERT INTO producten (type,bouwjaar,prijs,image)
  85. // VALUES ("A4")
  86. mysqli_query($conn, $sql);
  87. $lastID = mysqli_insert_id($conn); // EXTRA VOOR DEZE OPDRACHT
  88. mysqli_close($conn);
  89. return $lastID;
  90. }
  91.  
  92. // make function array weg te schrijven
  93. /* function insertArray($array, $table)
  94. {
  95. $this->conn = conn();
  96.  
  97. foreach($array)
  98.  
  99. // INSERT INTO landen (name) VALUES (Duitsland)
  100. $sql = "INSERT INTO ".$table." (".$colums.") VALUES (".$values.")";
  101.  
  102. // INTERT INTO producten (type,bouwjaar,prijs,image)
  103. // VALUES ("A4")
  104. mysqli_query($conn, $sql);
  105. $lastID = mysqli_insert_id($conn); // EXTRA VOOR DEZE OPDRACHT
  106. mysqli_close($conn);
  107. return $lastID;
  108.  
  109. }*/
  110. }
  111. ?>
  112.  
  113.  
  114. <!-- this is my index.php -->
  115.  
  116. <?php
  117. require('inc/Database.php');
  118.  
  119. $database = new database("localhost","root","", "rocthat");
  120. ?>
  121. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  122. <html>
  123. <head>
  124. <title>Home</title>
  125. <link href="./css/reset.css" type="text/css" rel="stylesheet" />
  126. <link href="./css/myStylesheet.css" type="text/css" rel="stylesheet" />
  127. <meta name="keywords" content="Roc that, rocthat, roc that, muziek" />
  128. <meta name="description" content="This is the main page of Roc That" />
  129. <meta name="author" content="Kevin Neven" />
  130. <meta name="copyright" content="1-10-2015" />
  131. </head>
  132. <body>
  133. <?php
  134.  
  135.  
  136. $data = $database->selectWhere("html", "html", "html.name = 'header'");
  137.  
  138.  
  139. while($row = mysqli_fetch_assoc($data))
  140. {
  141. $header[] = $row;
  142. }
  143. foreach($header as $header)
  144. {
  145. echo $header;
  146. }
  147.  
  148. /*echo "<div class='header'>
  149. <img src= './img/header/Header.png' align='center'>
  150.  
  151.  
  152. <ul class='menu'>
  153. <li><a href='index.html'>Homepage</a></li>
  154. <li><a href='contact.html'>Contact</a></li>
  155. <li><a href='tour.html'>The tour</a></li>
  156. <li><a href='discography.html'>discography</a></li>
  157. <li><a href='gallery.html'>Gallery</a></li>
  158. <li><a href='fanpage.html'>Fanpage</a></li>
  159. <li><a href='theband.html'>The band</a></li>
  160.  
  161. </ul>
  162. </div>";*/?>
  163. <div class="mainDiv">
  164.  
  165.  
  166.  
  167. <!-- images : height: 60px; -->
  168. <!-- menu : width: 180px; -->
  169. <!-- place 6 menu-items (links) to 6 different documents -->
  170. <!--
  171. the documents (pages) :
  172. homepage : index.html
  173. contactpage : contact.html
  174. about page : about.html
  175. discography : discography.html
  176. tour page : tour.html
  177. gallery : gallery.html
  178. -->
  179. <!-- place the links into a list -->
  180.  
  181. <div class="content">
  182. <h1>Homepage</h1>
  183. <p style="margin-top: 30px;">
  184. Hi there! This is the website of Roc That.<br />
  185. In our website you can find our webshop and pictures and all sorts of things.
  186. </p>
  187. </div>
  188.  
  189. <!-- content and width will be defined automatically -->
  190.  
  191. <!-- footer : height: 90px; -->
  192. <div class="footer">
  193. <table>
  194. <tr>
  195. <td>
  196. test
  197. </td>
  198. <td>
  199. test
  200. </td>
  201. <td>
  202. test
  203. </td>
  204. </tr>
  205. </table>
  206. </div>
  207. </div>
  208. </body>
  209. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement