Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class database {
- private $pdo;
- public function __construct() {
- // Connection information
- $host = 'localhost:3307';
- $dbname = 'stage';
- $user = 'root';
- $pass = 'usbw';
- // Attempt DB connection
- try
- {
- $this->pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
- $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- //echo 'Successfully connected to the database!';
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- function train_add() {
- $sql = "INSERT INTO train_information "
- . "(train_id, image, train_name, tare_weight, number_of_bogies, number_of_axles, wheel_diameter_min, wheel_diameter_max)"
- . "VALUES (train_id, :image, :train_name, :tare_weight, :number_of_bogies, :number_of_axles, :wheel_diameter_min, :wheel_diameter_max) ";
- $sth = $this->pdo->prepare($sql);
- $sth->bindParam(':image', $_POST['image'], PDO::PARAM_STR);
- $sth->bindParam(':train_name', $_POST['train_name'], PDO::PARAM_STR);
- $sth->bindParam(':tare_weight', $_POST['tare_weight'], PDO::PARAM_STR);
- $sth->bindParam(':number_of_bogies', $_POST['number_of_bogies'], PDO::PARAM_STR);
- $sth->bindParam(':number_of_axles', $_POST['number_of_axles'], PDO::PARAM_STR);
- $sth->bindParam(':wheel_diameter_min', $_POST['wheel_diameter_min'], PDO::PARAM_STR);
- $sth->bindParam(':wheel_diameter_max', $_POST['wheel_diameter_max'], PDO::PARAM_STR);
- $sth->execute();
- $id=$this->pdo->lastInsertID();
- echo 'last inserted id: ' . $id;
- }
- function login() {
- $sql = "SELECT user_id, country_id, first_name, login_name, password FROM user WHERE login_name = :login_name";
- $sth = $this->pdo->prepare($sql);
- $sth->bindParam(':login_name', $_POST['login_name'], PDO::PARAM_STR);
- $sth->execute();
- if (($row = $sth->fetchObject())) {
- if ($_POST['password'] == $row->password) {
- session_start();
- $_SESSION['first_name'] = $row->first_name;
- $_SESSION['login_name'] = $row->login_name;
- header('Location: login_succes.php');
- }
- /*If the password/email_adres is inccorect. it gives you a warning message*/
- else { ?>
- <div id='login_fail'>Password is incorrect. <br /> Click <a href='index.php'>here</a> to go back
- <?php }
- } else { ?>
- <div id='login_fail'>Username is incorrect. <br /> Click <a href='index.php'>here</a> to go back
- <?php }
- }
- function getAllAssoc() {
- $sql = "SELECT * FROM train_information WHERE train_name = :train_name";
- $sth = $this->pdo->prepare($sql);
- $sth->bindParam(":train_name", $_POST["train_name"]);
- $sth->execute();
- return $sth->fetchAll();
- }
- function selector() {
- $sql = "SELECT train_name, train_id FROM train_information";
- $sth = $this->pdo->prepare($sql);
- $sth->execute();
- return $sth->fetchAll();
- }
- function expand_info() {
- $sql = "SELECT * FROM train_information WHERE train_id = :train_id";
- $sth = $this->pdo->prepare($sql);
- $sth->bindParam(":train_id", $_GET["train_id"], PDO::PARAM_STR);
- $sth->execute();
- return $sth->fetchAll();
- }
- /*Werkt nog niet*/
- function axles(){
- $id = $this->train_add()->$id;
- $sql = "Select axle_id FROM axle WHERE train_id = :id";
- $sth = $this->pdo->prepare($sql);
- $sth = bindParam(':id', $id);
- $sth->execute();
- return $sth->fetchAll();
- $row = mysql_fetch_array($sql);
- echo $row['train_id'];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement