1
0
Fork 0
template/functions/sql.php

35 lines
644 B
PHP
Raw Permalink Normal View History

2024-04-25 21:55:08 +02:00
<?php
2024-06-09 18:08:35 +02:00
function sql($query, $array = [], $method = null) {
2024-04-25 21:55:08 +02:00
global $sql;
try {
if($method == 'count') {
2024-06-09 18:08:35 +02:00
$prepare = $sql->query($query);
2024-04-25 21:55:08 +02:00
$prepare->execute($array);
$data = $prepare->fetchColumn();
return $data;
2024-06-09 18:08:35 +02:00
} elseif($method == 'insert') {
$prepare = $sql->prepare($query);
$prepare->execute($array);
2024-04-25 21:55:08 +02:00
} elseif($method == 'fetch') {
2024-06-09 18:08:35 +02:00
$prepare = $sql->query($query);
2024-04-25 21:55:08 +02:00
$prepare->execute($array);
2024-06-09 18:08:35 +02:00
return $prepare->fetch();
2024-04-25 21:55:08 +02:00
} else {
2024-06-09 18:08:35 +02:00
$prepare = $sql->prepare($query);
2024-04-25 21:55:08 +02:00
$prepare->execute($array);
2024-06-09 18:08:35 +02:00
return $prepare->fetchAll();
2024-04-25 21:55:08 +02:00
}
} catch(Exception $e) {
throw($e);
}
}
2024-06-09 18:08:35 +02:00
?>