MySQL 存储函数出现访问冲突 :1305 in Laravel but works in phpmyadmin

标签 mysql laravel-4 eloquent

我在本地数据库中定义了以下存储函数:

CREATE DEFINER=`root`@`localhost` FUNCTION `GenerateSectionFee`(`in_month` INT, `in_year` INT, `in_section_detail_id` INT, `in_issue_date` DATE, `in_due_date` DATE) RETURNS int(11)
    MODIFIES SQL DATA
BEGIN    
    /** Variables declartion **/
    declare v_new_mfm_id int;


    /** insert heads of given grade & section **/
    insert into month_fees_masters(section_details_id, fee_month, fee_year, issue_date, due_date,  h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, 
        th1, th2, th3, th4, th5, th6, th7, th8, th9, th10)
    select  
        class_detail_id, in_month, in_year, in_issue_date, in_due_date, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, 
        th1, th2, th3, th4, th5, th6, th7, th8, th9, th10 
    from fee_masters 
    where class_detail_id=in_section_detail_id and fee_type='R';

    /** Get id of inserted record **/
    SELECT LAST_INSERT_ID() into v_new_mfm_id;

    /** insert monthly fee of all students of given grade & section **/
    insert into month_fees(month_fees_masters_id, student_id, arears, fine_amount, fee_con, deposit_amount, status)
    select 
        v_new_mfm_id, s.id, (f.arears+f.fine_amount-f.fee_con-f.deposit_amount), 0 fine_amount, s.fee_con, 0 deposit_amount, 'L' status 
    from
        students s inner join month_fees f on s.id=f.student_id and f.status='L'
    where 
        s.cur_class_detail_id = in_section_detail_id and s.status='ACTIVE'
    ;

return (0); /** Zero means No Error. Records created successfully **/
END

当我从 phpmyadmin 调用它时,它工作正常。但是当我从 Laravel 调用它时,它会给出以下错误:

[2014-11-03 05:53:54] production.ERROR: exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1305 PROCEDURE iiui_db.GenerateSectionFee does not exist (SQL: call GenerateSectionFee(10, 2014, 27, 2014-10-01, 2014-10-08))' in C:\wamp\www\SchoolWeb\vendor\laravel\framework\src\Illuminate\Database\Connection.php:555

我从 Laravel 调用此函数,如下所示:

$flag_ = DB::statement('call GenerateSectionFee(?, ?, ?, ?, ?)', $data);

而$data是一个数组。

最佳答案

CALL 与存储过程一起使用 - doc ,而对于您执行的功能:

select function(args)

所以在你的情况下:

$flag_ = DB::statement('select GenerateSectionFee(?, ?, ?, ?, ?)', $data);

关于MySQL 存储函数出现访问冲突 :1305 in Laravel but works in phpmyadmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26709247/

相关文章:

python - syncdb 不会为嵌套模型创建表

sql - 查看存储过程结果后的自定义结果

php - 为什么 Eloquent 在插入数据库时​​看不到模型中的所有字段

laravel - 如何在 Eloquent 中使用 join 和 sum?

php - Laravel 5.2 Eloquent

php mysql 插入/更新字段名称显示

php - 如何在 MySQL 表中存储格式化文本?

php - Laravel 使用哈希作为验证器

php - Laravel 4 级联软删除

laravel - 如何为 Laravel paginate() 方法分配列名称