change datetime not null default 0000

This commit is contained in:
xiaomlove
2022-04-05 14:52:50 +08:00
parent 8bee181c09
commit bd1fe9a474
5 changed files with 81 additions and 13 deletions

View File

@@ -267,7 +267,7 @@ class NexusDB
return DB::transaction($callback, $attempts);
}
public static function getMysqlColumnInfo($table, $column)
public static function getMysqlColumnInfo($table, $column = null)
{
static $driver;
$config = nexus_config('nexus.mysql');
@@ -276,11 +276,22 @@ class NexusDB
$driver->connect($config['host'], $config['username'], $config['password'], 'information_schema', $config['port']);
}
$sql = sprintf(
"select * from COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s' and COLUMN_NAME = '%s'",
$config['database'], $table, $column
"select * from COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'",
$config['database'], $table
);
if ($column !== null) {
$sql .= " and COLUMN_NAME = '$column'";
}
$res = $driver->query($sql);
return $driver->fetchAssoc($res);
if ($column !== null) {
return $driver->fetchAssoc($res);
}
$results = [];
while ($row = $driver->fetchAssoc($res)) {
$results[$row['COLUMN_NAME']] = $row;
}
return $results;
}