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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?