pass parameters in insert query stored procedure i

2019-02-21 03:10发布

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');
    }
}

1条回答
Melony?
2楼-- · 2019-02-21 03:38

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) . ')');
查看更多
登录 后发表回答