如何使用原始数据库字符串在laravel 5.5中创建 新表?
using (StreamReader reader = new StreamReader(stream2, Encoding.UTF8))
{
str6 = reader.ReadToEnd();
}
我知道有一个 Illuminate \ Support \ Facades \ Schema 用于制作新表,
$createTableSqlString =
"CREATE TABLE $newTableName (
product_id INT(11) NOT NULL AUTO_INCREMENT,
...
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;";
但是我该如何定义或给它原始字符串Schema::connection('mysqlInvsys')->create(...);
?我在official doc中找不到任何示例。
答案 0 :(得分:5)
Laravel提供了运行原始SQL查询的功能,如here所示。
对于表格创建,您可以使用DB::statement($createTableSqlString)