How to get rid of MySQL error 'Prepared statement needs to be re-prepared'

后端 未结 7 1462
夕颜
夕颜 2020-11-27 07:43

I\'ve rewritten my site php-code and added MySQL Stored Procedures.

In my local version everything works fine but after I uploaded my site to hosting server I\'m co

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 08:24

    This is a workaround for people who are on shared hosting and don't want to risk it with sql injection. According to this post: Laravel Fluent Query Builder Join with subquery you could store the definition of your view in a function

    private function myView(){
        return DB::raw('(**definition of the view**) my_view_name)');
    }
    

    and then use it like this:

    public function scopeMyTable(Builder $query)
    {
        return $query->join($this->myView(),'my_view_name.id','=','some_table.id');
    }
    

    This is a laravel approach, but I'm sure it could be applied in most cases and doesn't need huge code refactoring or architecture change. Plus, it's relatively secure as your statements stay prepared

提交回复
热议问题