我正在尝试将现有数据从 MySQL 数据库导出到可以运行的 ruby 命令中rake db:seed
。
这是我的代码。
# Generate db:seed data for proveedores.
$proveedores = R::findAll('tbproveedores');
$proveedoresE = R::exportAll($proveedores);
foreach ($proveedoresE as &$p) {
$line = 'BookSupplier.create(company: "%s", city: "%s", country: "%s", address: "%s", telephone: "%s", contact: "%s", email: "%s", website: "%s"\n';
$exportedLine = sprintf($line, $p['empresa'], $p['ciudad'], $p['pais'], $p['direccion'], $p['telefono'], $p['personacontacto'], $p['email'], $p['website']);
var_dump($exportedLine);
fwrite($seeds, $exportedLine);
echo "<br />";
}
注意\n
$line 变量末尾的换行符。我在网上读到这就是使用换行符所需的全部内容。
我上面的代码的输出是(逐字,很长的一行):
BookSupplier.create(company: "Pearson", city: "Lima", country: "Peru", address: "Av. Limon", telephone: "4673535421", contact: "Javier", email: "", website: ""\nBookSupplier.create(company: "Project Management Institute - PMI", city: "Pennsylvania", country: "Estados Unidos", address: "Newtown Square, Pennsylvania", telephone: "1", contact: "Limberg Morales", email: "", website: "http://www.pmi.org/"\nBookSupplier.create(company: "UVirtual - Centro de Excelencia", city: "Santa Cruz", country: "Bolivia", address: "Av. Irala 585", telephone: "1", contact: "Limberg Morales", email: "", website: ""\nBookSupplier.create(company: "Ábaco de Rodolfo Depalma", city: "Buenos Aires", country: "Argentina", address: "Viamonte 1336, 4° (C1053 ACB) Buenos Aires", telephone: "5411-43711675", contact: "Limberg Morales", email: "", website: "http://www.abacoeditorial.com.ar/"\nBookSupplier.create(company: "Pablo Lledó - ProjectManagement", city: "Canadá", country: "Estados Unidos", address: "Victoria, BC, Canadá", telephone: "1", contact: "Limberg Morales", email: "", website: ""\n
在我插入换行符之后,我希望每个调用都在它自己的行中。关于我做错了什么有什么建议吗?