function connectDB() {
try {
$errorMessage = 'Ошибка подключения к базе данных';
$DB = 'mysql:host='.DB_HOST.';dbname='.DB_NAME;
$conn = new PDO($DB, DB_USER, DB_PASSWORD);
$conn ->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
return $conn;
}
catch(PDOException $e) {
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
throw new Exception($errorMessage);
}
}
function getParameters($default = '') {
$data = [
'surname' => isset($_POST['surname']) ? trim(mb_strtolower($_POST['surname'])) : $default,
'name' => isset($_POST['name']) ? trim(mb_strtolower($_POST['name'])) : $default,
'fathername' => isset($_POST['fathername']) ? trim(mb_strtolower($_POST['fathername'])) : $default,
'phone' => isset($_POST['phone']) ? trim(preg_replace('/[^0-9,+]/', '',($_POST['phone']))) : $default,
'email' => isset($_POST['email']) ? trim(mb_strtolower($_POST['email'])) : $default,
];
return $data;
}
function checkPeople($data,$conn){
$query = "SELECT * FROM `orders2022` WHERE LOWER(`surname`) LIKE CONCAT('%', ?, '%') AND LOWER(`name`) LIKE CONCAT('%', ?, '%') AND LOWER(`fathername`) LIKE CONCAT('%', ?, '%')";
$stmt = $conn -> prepare ($query);
$stmt->execute([$data['surname'], $data['name'], $data['fathername']]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}
Мне необходимо только узнать есть ли такой заказчик с такими данными.
SELECT *
FROM `orders2022`
WHERE LOWER(`surname`) LIKE CONCAT('%', ?, '%')
AND LOWER(`name`) LIKE CONCAT('%', ?, '%')
AND LOWER(`fathername`) LIKE CONCAT('%', ?, '%')
function connectDB() {
try {
$DB = 'mysql:host='.DB_HOST.';dbname='.DB_NAME;
$conn = new PDO($DB, DB_USER, DB_PASSWORD);
$conn ->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
return $conn;
}
catch(PDOException $e) {
$errorMessage = 'Ошибка подключения к базе данных';
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
throw new Exception($errorMessage);
}
}
function getParameters($default = '') {
$data = [
'surname' => isset($_POST['surname']) ? trim(mb_strtolower("%{$_POST['surname']}%")) : $default,
'name' => isset($_POST['name']) ? trim(mb_strtolower("%{$_POST['name']}%")) : $default,
'fathername' => isset($_POST['fathername']) ? trim(mb_strtolower("%{$_POST['fathername']}%")) : $default,
'phone' => isset($_POST['phone']) ? trim(preg_replace('/[^0-9,+]/', '',($_POST['phone']))) : $default,
'email' => isset($_POST['email']) ? trim(mb_strtolower($_POST['email'])) : $default,
'date' => isset($_POST['date']) ? trim(mb_strtolower($_POST['date'])) : $default,
];
return $data;
}
function checkPeople($data,$conn){
$query = "SELECT *
FROM `orders`
WHERE ((LOWER(`surname`) LIKE ?
AND LOWER(`name`) LIKE ?
AND LOWER(`fathername`) LIKE ?)
OR (LOWER(`email`) LIKE ?)
OR (`phone` LIKE ?))
AND (`date` = ?)
LIMIT 1";
$stmt = $conn -> prepare ($query);
$stmt->execute([$data['surname'], $data['name'], $data['fathername']], $data['email'], $data['phone'], $data['date']);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}