65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
function handle_pdo_exception($e) {
|
|
print "Error!: " . $e->getMessage() . "<br/>";
|
|
die();
|
|
}
|
|
|
|
function get_Station() {
|
|
try {
|
|
$dbh = new PDO('mysql:host=mysql;dbname=ksp', 'grisu', 'secret');
|
|
foreach($dbh->query('SELECT * from Station') as $row) {
|
|
print_r($row);
|
|
}
|
|
$dbh = null;
|
|
} catch(PDOException $e) {
|
|
handle_pdo_exception($e);
|
|
}
|
|
}
|
|
|
|
function check_user_id($con, $user_id) {
|
|
try {
|
|
$stmt = $con->prepare('SELECT user_id FROM users WHERE user_id = :user_id limit 1');
|
|
$stmt->execute(['user_id' => $user_id]);
|
|
|
|
if($stmt) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} catch(PDOException $e) {
|
|
handle_pdo_exception($e);
|
|
}
|
|
}
|
|
|
|
function get_user_data_name($con, $user_name) {
|
|
try {
|
|
$stmt = $con->prepare('SELECT * FROM users WHERE user_name = :user_name limit 1');
|
|
$stmt->execute(['user_name' => $user_name]);
|
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
|
return $stmt->fetch();
|
|
} catch(PDOException $e) {
|
|
handle_pdo_exception($e);
|
|
}
|
|
}
|
|
|
|
function get_user_data_id($con, $user_id) {
|
|
try {
|
|
$stmt = $con->prepare('SELECT * FROM users WHERE user_id = :user_id limit 1');
|
|
$stmt->execute(['user_id' => $user_id]);
|
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
|
return $stmt->fetch();
|
|
} catch(PDOException $e) {
|
|
handle_pdo_exception($e);
|
|
}
|
|
}
|
|
|
|
function add_user($con, $username, $user_id, $user_group, $password, $salt) {
|
|
try {
|
|
$stmt = $con->prepare("INSERT INTO users (user_id, password, user_name, salt, user_group) VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->bind_param("sssss", $user_id, $password, $username, $salt, $user_group);
|
|
$stmt->execute();
|
|
} catch(PDOExeption $e) {
|
|
handle_pdo_exception($e);
|
|
}
|
|
} |