我使用以下内容以 csv 格式转储 sql 文件: $file_path = "/tmp/app_users.csv";
$sql = "SELECT 'id','username','name','email',
'phone_number','city',
'batch_code','course_type' UNION ALL
SELECT id, username, name, email,
phone_number, city, batch_code, course_type
FROM users INTO OUTFILE '".$file_path."' ".
"FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n'";
$db = Zend_Registry::get('db');
$stmt = $db->query($sql, array());
但是 users 表中的某些字段为空,在 csv 输出中显示为 \N。我希望将其替换为字符串“NULL”。我尝试使用 str_replace,但它在每一行之后神秘地插入了一个额外的空白行。