• <bdo id='Y0x4J'></bdo><ul id='Y0x4J'></ul>

      1. <i id='Y0x4J'><tr id='Y0x4J'><dt id='Y0x4J'><q id='Y0x4J'><span id='Y0x4J'><b id='Y0x4J'><form id='Y0x4J'><ins id='Y0x4J'></ins><ul id='Y0x4J'></ul><sub id='Y0x4J'></sub></form><legend id='Y0x4J'></legend><bdo id='Y0x4J'><pre id='Y0x4J'><center id='Y0x4J'></center></pre></bdo></b><th id='Y0x4J'></th></span></q></dt></tr></i><div id='Y0x4J'><tfoot id='Y0x4J'></tfoot><dl id='Y0x4J'><fieldset id='Y0x4J'></fieldset></dl></div>

        <legend id='Y0x4J'><style id='Y0x4J'><dir id='Y0x4J'><q id='Y0x4J'></q></dir></style></legend><tfoot id='Y0x4J'></tfoot>

        <small id='Y0x4J'></small><noframes id='Y0x4J'>

        在 Laravel 4 迁移中创建 MYSQL 过程

        Creating MYSQL Procedure in Laravel 4 Migrations(在 Laravel 4 迁移中创建 MYSQL 过程)
        • <bdo id='vnlGz'></bdo><ul id='vnlGz'></ul>

            <i id='vnlGz'><tr id='vnlGz'><dt id='vnlGz'><q id='vnlGz'><span id='vnlGz'><b id='vnlGz'><form id='vnlGz'><ins id='vnlGz'></ins><ul id='vnlGz'></ul><sub id='vnlGz'></sub></form><legend id='vnlGz'></legend><bdo id='vnlGz'><pre id='vnlGz'><center id='vnlGz'></center></pre></bdo></b><th id='vnlGz'></th></span></q></dt></tr></i><div id='vnlGz'><tfoot id='vnlGz'></tfoot><dl id='vnlGz'><fieldset id='vnlGz'></fieldset></dl></div>

            <small id='vnlGz'></small><noframes id='vnlGz'>

            <legend id='vnlGz'><style id='vnlGz'><dir id='vnlGz'><q id='vnlGz'></q></dir></style></legend>
              <tbody id='vnlGz'></tbody>
              • <tfoot id='vnlGz'></tfoot>
                • 本文介绍了在 Laravel 4 迁移中创建 MYSQL 过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法在 Laravel 4 迁移中生成存储的 MYSQL 过程?

                  例如,这是一个存储为字符串的简单过程生成查询(通过 的源代码.您可以使用 PDO exec() DB::connection()->getPdo()->exec() 代替

                  也就是说,虚拟tags 表的示例迁移可能如下所示

                  class CreateTagsTable extends Migration {/*** 运行迁移.** @return 无效*/公共函数 up(){Schema::create('tags', function($table){$table->increments('id');$table->string('name')->unique();});$sql = <<<SQL如果存在则删除程序 sp_insert_tag;创建程序 sp_insert_tag(IN _name VARCHAR(32))开始INSERT INTO `tags`(`name`) VALUES(_name);结尾SQL;DB::connection()->getPdo()->exec($sql);}/*** 反转迁移.** @return 无效*/公共函数 down(){$sql = "DROP PROCEDURE IF EXISTS sp_insert_tag";DB::connection()->getPdo()->exec($sql);架构::drop('标签');}}

                  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)

                      $query = <<<SQL
                  DELIMITER $$
                  DROP PROCEDURE IF EXISTS test$$
                  CREATE PROCEDURE test()
                  BEGIN
                      INSERT INTO `test_table`(`name`) VALUES('test');
                  END$$
                  DELIMITER ;
                  SQL;
                  
                      DB:statement(DB::RAW($query));
                  


                  When Running this in a migration's up() function I get this error:

                  解决方案

                  There are two major problems with your code

                  1. 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.
                  2. You can't use DB::statement to execute CREATE PROCEDURE code because it uses prepared statement source code for Connection. You can use PDO exec() DB::connection()->getPdo()->exec() instead

                  That being said a sample migration for imaginary tags table might look like this

                  class CreateTagsTable extends Migration {
                  
                      /**
                       * Run the migrations.
                       *
                       * @return void
                       */
                      public function up()
                      {
                          Schema::create('tags', function($table){
                              $table->increments('id');
                              $table->string('name')->unique();
                          });
                  $sql = <<<SQL
                  DROP PROCEDURE IF EXISTS sp_insert_tag;
                  CREATE PROCEDURE sp_insert_tag(IN _name VARCHAR(32))
                  BEGIN
                      INSERT INTO `tags`(`name`) VALUES(_name);
                  END
                  SQL;
                          DB::connection()->getPdo()->exec($sql);
                      }
                  
                      /**
                       * Reverse the migrations.
                       *
                       * @return void
                       */
                      public function down()
                      {
                          $sql = "DROP PROCEDURE IF EXISTS sp_insert_tag";
                          DB::connection()->getPdo()->exec($sql);
                          Schema::drop('tags');
                      }
                  }
                  

                  这篇关于在 Laravel 4 迁移中创建 MYSQL 过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                  <tfoot id='E5O2O'></tfoot>
                  • <legend id='E5O2O'><style id='E5O2O'><dir id='E5O2O'><q id='E5O2O'></q></dir></style></legend>
                    • <bdo id='E5O2O'></bdo><ul id='E5O2O'></ul>

                        • <i id='E5O2O'><tr id='E5O2O'><dt id='E5O2O'><q id='E5O2O'><span id='E5O2O'><b id='E5O2O'><form id='E5O2O'><ins id='E5O2O'></ins><ul id='E5O2O'></ul><sub id='E5O2O'></sub></form><legend id='E5O2O'></legend><bdo id='E5O2O'><pre id='E5O2O'><center id='E5O2O'></center></pre></bdo></b><th id='E5O2O'></th></span></q></dt></tr></i><div id='E5O2O'><tfoot id='E5O2O'></tfoot><dl id='E5O2O'><fieldset id='E5O2O'></fieldset></dl></div>

                          <small id='E5O2O'></small><noframes id='E5O2O'>

                            <tbody id='E5O2O'></tbody>