在 Laravel 4 迁移中创建 MYSQL 过程
本文介绍了在 Laravel 4 迁移中创建 MYSQL 过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 Laravel 4 迁移中生成存储的 MYSQL 过程?
例如,这是一个存储为字符串的简单过程生成查询(通过 的源代码.您可以使用 PDO exec()
DB::connection()->getPdo()->exec()
代替
也就是说,虚拟tags
表的示例迁移可能如下所示
Is there a way to generate stored MYSQL procedures in a Laravel 4 migration?
For example, here's a simple procedure generation query stored as a string (via a Heredoc)
When Running this in a migration's up()
function I get this error:
解决方案
There are two major problems with your code
DELIMITER
is not a valid sql statement. It's just a MySql client command. So just don't use it. BTW the error you get tells you exactly that.- You can't use
DB::statement
to executeCREATE PROCEDURE
code because it uses prepared statement source code forConnection
. You can use PDOexec()
DB::connection()->getPdo()->exec()
instead
That being said a sample migration for imaginary tags
table might look like this
这篇关于在 Laravel 4 迁移中创建 MYSQL 过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!