/\/([^\/]+)$/
<?php
$url = 'https://www.domain.ru/test-url';
// using preg_match
preg_match('/(\/[^\/]+)$/', $url, $matches);
echo $matches[1].PHP_EOL;
// using parse_url
echo parse_url($url, PHP_URL_PATH);
select * from t1
where type = 4444 and date between '2017-5-4-12.00.00' and '2017-5-4-17.59.59';
with objects as (
select idObject
from tbl
where idProperty in (1,4)
group by idObject
having count(distinct idProperty) = 2
)
select * from tbl join objects using(idObject);
with data as (select
id,
a, b, c,
row_number() over (partition by a,b order by id) rn
from t
) select id,a, b, c from data where rn = 1;
<?php
class A
{
protected $sql = null;
public function setSQL()
{
$this->sql = "SELECT * FROM users WHERE id = 123";
return $this;
}
public function getSQL()
{
return $this->sql;
}
}
class B extends A
{
public function addSQL()
{
$this->sql .= " AND name = 'Alex'";
return $this;
}
}
$a = new A();
$b = new B();
echo $b->setSQL()->addSQL()->getSQL();
<?php
$query = "SELECT DATE(`time`) `Day`, SUM(`Profit`) `DaylyProfit`
FROM `history`
WHERE `type` = 1 AND `time` > DATE_SUB(CURRENT_DATE, INTERVAL 6 DAY)
GROUP BY `Day`
ORDER BY `Day` DESC;";
$result = $mysqli->query($query);
$all = $result -> fetch_all(MYSQLI_ASSOC);
echo json_encode($all);
update t set
time_from = LOWER(time_from),
nullable = IF(nullable is null or nullable = '', 1, nullable)
;
SELECT
*
FROM
information_schema.columns
WHERE
table_schema = 'schema_name'
AND table_name = 'table_name';
create table books (
ID INT,
AUTHOR VARCHAR
);
SELECT
*
FROM
information_schema.columns
WHERE table_name = 'books';
<?php
$otp1start = "2021-11-10";
$otp1end = "2021-11-20";
$now_date = date("Y-m-d");
if ($now_date > $otp1end) {
echo "Отпуск уже прошел";
} elseif ($now_date >= $otp1start) {
echo "Сотрудник в отпуске";
} else {
echo "Отпуск еще не наступил";
}
?>
SELECT AUTHOR
FROM POSSESSION
INNER JOIN BOOKS ON BOOK_ID = BOOKS.ID
WHERE TAKING_DATE > (CURRENT_DATE - INTERVAL '1 year')
GROUP BY AUTHOR
ORDER BY COUNT(AUTHOR) DESC
FETCH FIRST 1 ROWS WITH TIES;
SELECT
COUNT(DISTINCT CASE WHEN people.gender = 'M' THEN list.id END) AS mens,
COUNT(DISTINCT CASE WHEN people.gender = 'F' THEN list.id END) AS womens,
COUNT(DISTINCT CASE WHEN people.gender IS NULL THEN list.id END) AS unknown
FROM ListTable AS list
LEFT JOIN PeopleTable AS people ON (list.userID = people.id)
;
SELECT
chains.name,
ROUND(AVG(rate), 2) avg_rate
FROM Establishment
JOIN Review ON Review.establishment_id = Establishment.id
JOIN Rate ON Rate.review_id = Review.id
JOIN Establishment chains ON chains.id = COALESCE(Establishment.chain_id, Establishment.id)
GROUP BY chains.name
ORDER BY avg_rate DESC
;
<?php
$board = [
'a' => [
'1' => '',
'2' => '',
'3' => '',
'4' => '',
'5' => '',
'6' => '',
'7' => '',
'8' => '',
],
'b' => [
'1' => 'белый конь',
'2' => '',
'3' => '',
'4' => '',
'5' => '',
'6' => '',
'7' => '',
'8' => '',
],
// ---
'g' => [
'1' => '',
'2' => '',
'3' => '',
'4' => '',
'5' => '',
'6' => '',
'7' => '',
'8' => '',
],
'h' => [
'1' => '',
'2' => '',
'3' => '',
'4' => '',
'5' => '',
'6' => '',
'7' => '',
'8' => '',
]
];
// ход конем b1 -> a3
$board['a']['3'] = 'белый конь';
$board['b']['1'] = '';
print_r($board);
select
office_id,
json_arrayagg(employee_id) employee_ids
from t
group by office_id;
+===========+==============+
| office_id | employee_ids |
+===========+==============+
| 1 | [1, 2] |
+-----------+--------------+
<?php
$start = microtime(TRUE);
sleep(3);
$diff = microtime(TRUE) - $start;
printf('Execution time: %s s', $diff);
\/([^\/]+)$
<?php
$path = 'D:\domains\99ballov/frontend/web//images/user/76/support/Screenshot_20211020-143428_WhatsApp_1637057308.jpg';
// using preg_match
preg_match('/\/([^\/]+)$/', $path, $matches);
echo $matches[1].PHP_EOL;
// using basename
echo basename($path).PHP_EOL;