dsovc00684 2014-03-27 19:57
浏览 135
已采纳

PHP和Mysql多次更新 - allowMultiQueries等效

I have just started working with Laravel and I was wondering if there was an equivalent of the allowMultiQueries connection string parameter that I would use in java.

Is there way to do multiple updates in the same call or do they have to be done in succession?

DB::update('DROP TABLE IF EXISTS tablename; CREATE TABLE tablename(...);');

instead of

DB::update('DROP TABLE IF EXISTS tablename;'); 
DB::update('CREATE TABLE tablename(...);');
  • 写回答

1条回答 默认 最新

  • drygauost253590142 2014-03-28 03:25
    关注

    You can do it fluently the Laravel way using Schema Builder like so

    use Illuminate\Database\Schema\Blueprint;
    
    ...
    
    if (Schema::hasTable('tablename')) {
        Schema::drop('tablename');
    }
    Schema::create('tablename', function(Blueprint $table) {
        $table->increments('id');
        $table->string('name', 64);
        $table->timestamps();
        $table->index('name');
    });
    

    But if you for some reason want to execute raw queries you can use unprepared() method in Query Builder

    DB::unprepared('DROP TABLE IF EXISTS tablename; CREATE TABLE tablename (id INT ...)');    
    

    but at least make sure you're using the proper syntax

    DROP TABLE IF EXISTS tablename
               ^^^^^^^^^
    

    instead of

    DROP TABLE tablename IF EXISTS
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画