JavaScript
- 3 ответа
- 0 вопросов
2
Вклад в тег
<?php
$config = [
'DB_USER' => 'root',
'DB_PASSWORD' => '****',
'DB_HOST' => 'localhost',
'DB_DRIVER' => 'mysql',
'DB_DATABASE' => 'test'
];
$pdoConfig = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
];
$dsn = $config['DB_DRIVER'] . ':host=' . $config['DB_HOST']
. ';dbname=' . $config['DB_DATABASE'];
try {
$pdo = new PDO(
$dsn,
$config['DB_USER'],
$config['DB_PASSWORD'],
$pdoConfig
);
$query = 'SELECT `username` FROM `data2` WHERE `username` = :username';
$stmt = $pdo->prepare($query);
$stmt->bindParam(':username', $_GET['username'], PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch();
echo json_encode($user);
} catch (PDOException $e) {
echo $e->getMessage();
}