laravel 在laravel 4 中的插入查询存储过程中传递参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18102537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:14:31  来源:igfitidea点击:

pass parameters in insert query stored procedure in laravel 4

phpmysqlstored-proceduresinsertlaravel

提问by user2655547

I have created a procedure for insertion but dont know how to call parameters "name" and "path" in controller and model

我创建了一个插入过程,但不知道如何在控制器和模型中调用参数“名称”和“路径”

Stored procedure:

存储过程:

CREATE DEFINER=`root`@`localhost` 
     PROCEDURE `insert_document_details`
        (IN `name` VARCHAR(50), IN `path` VARCHAR(255) )
BEGIN
    INSERT INTO `document_details`
      (`document_name`, `document_path`) 
    VALUES (name,path);
END

Routes:

路线:

Route::post('insert_document_details/{name}/{path}',array('as'=>'insert_document_details',
'uses'=>'AuthorsController@post_document_details'));

AuthorController:

作者控制器:

class AuthorsController extends BaseController{
        public $restful = true;

        public function post_document_details($name,$path)
        {

            $document_details=Response::json(Author::insert_document_details_Call());
            return $document_details;
        }
}

Author(model):

作者(模特):

class Author extends Eloquent {

    public $table = 'document_details';
    protected $primaryKey = 'id';

    public static function insert_document_details_Call($name,$path)
    {
        return DB::select('call insert_document_details');
    }
}

回答by Abishek

The second takes a list of parameters that can be passed as below

第二个需要一个可以传递的参数列表,如下所示

DB::select('call insert_document_details(?,?)',array($name,$path));

or

或者

DB::statement('call insert_document_details(' . DB::raw($name) . ',' . DB::raw($path) . ')');