Advertisement
Mr_MitchW

Untitled

Apr 7th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. <?php
  2. class database {
  3. private $pdo;
  4.  
  5. public function __construct() {
  6. // Connection information
  7. $host = 'localhost:3307';
  8. $dbname = 'stage';
  9. $user = 'root';
  10. $pass = 'usbw';
  11.  
  12. // Attempt DB connection
  13. try
  14. {
  15. $this->pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
  16. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17. //echo 'Successfully connected to the database!';
  18. }
  19. catch(PDOException $e)
  20. {
  21. echo $e->getMessage();
  22. }
  23. }
  24. function train_add() {
  25. $sql = "INSERT INTO train_information "
  26. . "(train_id, image, train_name, tare_weight, number_of_bogies, number_of_axles, wheel_diameter_min, wheel_diameter_max)"
  27. . "VALUES (train_id, :image, :train_name, :tare_weight, :number_of_bogies, :number_of_axles, :wheel_diameter_min, :wheel_diameter_max) ";
  28. $sth = $this->pdo->prepare($sql);
  29. $sth->bindParam(':image', $_POST['image'], PDO::PARAM_STR);
  30. $sth->bindParam(':train_name', $_POST['train_name'], PDO::PARAM_STR);
  31. $sth->bindParam(':tare_weight', $_POST['tare_weight'], PDO::PARAM_STR);
  32. $sth->bindParam(':number_of_bogies', $_POST['number_of_bogies'], PDO::PARAM_STR);
  33. $sth->bindParam(':number_of_axles', $_POST['number_of_axles'], PDO::PARAM_STR);
  34. $sth->bindParam(':wheel_diameter_min', $_POST['wheel_diameter_min'], PDO::PARAM_STR);
  35. $sth->bindParam(':wheel_diameter_max', $_POST['wheel_diameter_max'], PDO::PARAM_STR);
  36. $sth->execute();
  37.  
  38. $id=$this->pdo->lastInsertID();
  39. echo 'last inserted id: ' . $id;
  40. }
  41.  
  42. function login() {
  43.  
  44. $sql = "SELECT user_id, country_id, first_name, login_name, password FROM user WHERE login_name = :login_name";
  45. $sth = $this->pdo->prepare($sql);
  46. $sth->bindParam(':login_name', $_POST['login_name'], PDO::PARAM_STR);
  47. $sth->execute();
  48.  
  49. if (($row = $sth->fetchObject())) {
  50. if ($_POST['password'] == $row->password) {
  51. session_start();
  52. $_SESSION['first_name'] = $row->first_name;
  53. $_SESSION['login_name'] = $row->login_name;
  54. header('Location: login_succes.php');
  55. }
  56. /*If the password/email_adres is inccorect. it gives you a warning message*/
  57. else { ?>
  58. <div id='login_fail'>Password is incorrect. <br /> Click <a href='index.php'>here</a> to go back
  59. <?php }
  60. } else { ?>
  61. <div id='login_fail'>Username is incorrect. <br /> Click <a href='index.php'>here</a> to go back
  62. <?php }
  63. }
  64.  
  65. function getAllAssoc() {
  66. $sql = "SELECT * FROM train_information WHERE train_name = :train_name";
  67. $sth = $this->pdo->prepare($sql);
  68. $sth->bindParam(":train_name", $_POST["train_name"]);
  69. $sth->execute();
  70. return $sth->fetchAll();
  71. }
  72.  
  73. function selector() {
  74. $sql = "SELECT train_name, train_id FROM train_information";
  75. $sth = $this->pdo->prepare($sql);
  76. $sth->execute();
  77. return $sth->fetchAll();
  78. }
  79.  
  80. function expand_info() {
  81. $sql = "SELECT * FROM train_information WHERE train_id = :train_id";
  82. $sth = $this->pdo->prepare($sql);
  83. $sth->bindParam(":train_id", $_GET["train_id"], PDO::PARAM_STR);
  84. $sth->execute();
  85. return $sth->fetchAll();
  86. }
  87.  
  88.  
  89. /*Werkt nog niet*/
  90. function axles(){
  91. $id = $this->train_add()->$id;
  92. $sql = "Select axle_id FROM axle WHERE train_id = :id";
  93. $sth = $this->pdo->prepare($sql);
  94. $sth = bindParam(':id', $id);
  95. $sth->execute();
  96. return $sth->fetchAll();
  97. $row = mysql_fetch_array($sql);
  98. echo $row['train_id'];
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement