Skip to content

Instantly share code, notes, and snippets.

@necmettin
Created January 26, 2023 02:12
Show Gist options
  • Save necmettin/7f523dcac8b67ca38f74f4640c2d1897 to your computer and use it in GitHub Desktop.
Save necmettin/7f523dcac8b67ca38f74f4640c2d1897 to your computer and use it in GitHub Desktop.
Find date and datetime fields with invalid values
<?php
function cmd_db_find_0000(): void
{
global $App;
$key = "Tables_in_bulundum_com";
$tables = field2array($App->RDB->run("SHOW TABLES"), $key);
foreach ($tables as $tablename)
{
$fields = $App->RDB->run("SHOW COLUMNS FROM `$tablename`");
foreach ($fields as $field)
{
if ($field['Type'] === 'datetime' || $field['Type'] === 'date')
{
$fieldname = $field['Field'];
$qstr = "SELECT Id FROM `$tablename` WHERE $fieldname LIKE '0000%'";
$rows = field2array($App->RDB->run($qstr));
if ($rows)
{
pp("$tablename: $fieldname");
pp($qstr);
ppj($rows);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment