MySQL queries for selecting records based on different time criteria using a timestamp integer field named created
.
SELECT
*
FROM
your_table
WHERE
“There are only two hard things in Computer Science: cache invalidation and naming things.”
— Phil Karlton
-- Remove all watchdog's records from a MySQL table except for the last 500. | |
DELETE FROM `watchdog` | |
WHERE wid NOT IN ( | |
SELECT wid | |
FROM ( | |
SELECT wid | |
FROM `watchdog` | |
ORDER BY wid DESC | |
LIMIT 500 |
<?php | |
use Drupal\Core\Database\Database; | |
use Drupal\Core\Database\Query\SelectInterface; | |
/** | |
* Returns a plain SQL query from a Select query object. | |
*/ | |
function get_plain_sql_query(SelectInterface $query): string | |
{ |
SetEnv APP_ENV prod SetEnv DATABASE_URL 'mysql://user:[email protected]:3306/dbname'
<?php | |
declare(strict_types=1); | |
/* | |
A pattern with multiple conditions: | |
- at least one digit. | |
- at least one lowercase letter (including special Scandinavian characters). | |
- at least one uppercase letter (including special Scandinavian characters). | |
- at least one character that is not a letter or a number (including special Scandinavian characters). |
<?php | |
namespace Drupal\your_module\Controller; | |
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | |
class YourController { | |
public function yourPage() { | |
// Some logic here... |