Created
January 26, 2023 02:12
-
-
Save necmettin/7f523dcac8b67ca38f74f4640c2d1897 to your computer and use it in GitHub Desktop.
Find date and datetime fields with invalid values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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