获取表的所有列及其类型信息

if (stripos($column_type, 'enum') !== false) {
    if ($row[$column_name] === null || $row[$column_name] === '') {
        $values[] = 'NULL';
    } else {
        $values[] = "'" . str_replace(array("\r", "\n"), array('\r', '\n'), $row[$column_name]) . "'";
    }
} else {
    $values[] = "'" . str_replace(array("\r", "\n"), array('\r', '\n'), $row[$column_name]) . "'";
}
    • 判断字段类型是否为 enum
    • 如果字段值为 null 或空字符串,则插入 NULL
    • 否则,正常插入值。

通过这种方式,可以确保 enum 类型的字段在值为 null 或空字符串时能够正确插入数据库。

posted @ 2024-10-03 23:07  黄文Rex  阅读(10)  评论(0)    收藏  举报