当前位置: 首页 > 知识库问答 >
问题:

Laravel 5-找不到MySQL存储过程

邴宏大
2023-03-14

问题:将L4代码转换为L5。2和am接收到以下错误:SQLSTATE[42000]:语法错误或访问冲突:1305 FUNCTION cr_debug。输入模块2不存在(SQL:调用填充天数表(20,“01/29/2016”))

更新:我不知道功能功能cr_debug。ENTER_MODULE2。我不知道那是从哪里来的。这似乎是导致这个问题的原因,因为这个函数在MySQL中不存在,我也不知道它是从哪里来的。在我的Laravel 5.2安装中使用代理Ransack,我只找到提到ENTER_MODULE2的日志文件,并在我的Laravel 4安装中进行文本搜索ENTER_MODULE2我只找到一个提到该文本的SQL转储。该转储列在下面。不过,我确实在我的存储过程中找到了对ENTER_MODULE2的引用。检查一下,稍后会回来。

SQL倾倒:

DECLARE cr_stack_depth INTEGER DEFAULT cr_debug.ENTER_MODULE2('FIRST_DAY', 'contracts', 8, 100430)/*[cr_debug.1]*/;

  CALL cr_debug.UPDATE_WATCH3('`firstday`', `firstday`, 'DATE', cr_stack_depth)/*[cr_debug.2]*/;

CALL cr_debug.TRACE(4, 4, 0, 5, cr_stack_depth)/*[cr_debug.2]*/;

CALL cr_debug.TRACE(5, 5, 2, 67, cr_stack_depth)/*[cr_debug.2]*/;

SET @devart_debug_ret = ADDDATE(LAST_DAY(SUBDATE(firstday, INTERVAL 1 MONTH)), 1)/*[cr_debug.2]*/;

CALL cr_debug.LEAVE_MODULE(cr_stack_depth - 1)/*[cr_debug.2]*/;

RETURN @devart_debug_ret;

CALL cr_debug.TRACE(6, 6, 0, 3, cr_stack_depth)/*[cr_debug.2]*/;

CALL cr_debug.LEAVE_MODULE(cr_stack_depth - 1)/*[cr_debug.2]*/;

END ;;
DELIMITER ;

尝试:我已经搜索了Stackoverflow和谷歌,以找到正在发生的事情。我试图改变调用到EXEC和创建另一个错误,说明我的版本的MySQL不支持调用。两周前我刚刚安装了最新版本的MySQL。我试图给过程调用命名空间,但没有成功。我已经从存储过程中的函数调用中删除了所有空格(例如:IF(var)现在是IF(var),或者函数(var)现在是函数(var)。我放弃了存储过程,并收到以下不同的错误: SQLSTATE[42000]:语法错误或访问冲突: 1305 PROCEDURE契约。POPULATE_DAYS_TABLE不存在(SQL: callPOPULATE_DAYS_TABLE(29,"01/29/2016"))

请求:如果可能的话,请协助找出错误,并详细解释我做错了什么。

注意:我已经严重缩短了ContractController。为简洁起见,请参阅php文件。如果您需要查看存储过程,我也可以显示它们。存储过程在MySQL中。这在拉威尔4中起作用。

调试信息:连接中出现2个PDO异常中的错误1。php第390行:SQLSTATE[42000]:语法错误或访问冲突:1305函数cr_debug。输入模块2不存在

in Connection.php line 390
at PDOStatement->execute(array()) in Connection.php line 390
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'call POPULATE_DAYS_TABLE(20, "01/29/2016")', array()) in Connection.php line 644
at Connection->runQueryCallback('call POPULATE_DAYS_TABLE(20, "01/29/2016")', array(), object(Closure)) in Connection.php line 611
at Connection->run('call POPULATE_DAYS_TABLE(20, "01/29/2016")', array(), object(Closure)) in Connection.php line 391
at Connection->statement('call POPULATE_DAYS_TABLE(20, "01/29/2016")')
at call_user_func_array(array(object(MySqlConnection), 'statement'), array('call POPULATE_DAYS_TABLE(20, "01/29/2016")')) in DatabaseManager.php line 317
at DatabaseManager->__call('statement', array('call POPULATE_DAYS_TABLE(20, "01/29/2016")')) in Facade.php line 218
at Facade::__callStatic('statement', array('call POPULATE_DAYS_TABLE(20, "01/29/2016")')) in computer.php line 15
at computer::storedProcedureCall('20', '01/29/2016') in ContractController.php line 56
at ContractController->store()
at call_user_func_array(array(object(ContractController), 'store'), array()) in Controller.php line 76
at Controller->callAction('store', array()) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(ContractController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(ContractController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ContractController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 703
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 705
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 678
at Router->dispatchToRoute(object(Request)) in Router.php line 654
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53

连接中出现2个QueryException中的第2个错误。php第651行:SQLSTATE[42000]:语法错误或访问冲突:1305函数cr_debug。输入模块2不存在(SQL:调用填充天数表(20,“01/29/2016”))

in Connection.php line 651
at Connection->runQueryCallback('call POPULATE_DAYS_TABLE(20, "01/29/2016")', array(), object(Closure)) in Connection.php line 611
at Connection->run('call POPULATE_DAYS_TABLE(20, "01/29/2016")', array(), object(Closure)) in Connection.php line 391
at Connection->statement('call POPULATE_DAYS_TABLE(20, "01/29/2016")')
at call_user_func_array(array(object(MySqlConnection), 'statement'), array('call POPULATE_DAYS_TABLE(20, "01/29/2016")')) in DatabaseManager.php line 317
at DatabaseManager->__call('statement', array('call POPULATE_DAYS_TABLE(20, "01/29/2016")')) in Facade.php line 218
at Facade::__callStatic('statement', array('call POPULATE_DAYS_TABLE(20, "01/29/2016")')) in computer.php line 15
at computer::storedProcedureCall('20', '01/29/2016') in ContractController.php line 56
at ContractController->store()
at call_user_func_array(array(object(ContractController), 'store'), array()) in Controller.php line 76
at Controller->callAction('store', array()) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(ContractController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(ContractController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ContractController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 703
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 705
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 678
at Router->dispatchToRoute(object(Request)) in Router.php line 654
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53

合同Controller.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Library\customer;
use App\Library\computer;

class ContractController extends Controller
{
    Protected $layout = 'master';
    public function store()
    {
        // Receive input from Form
        $input = \Input::only([
            'contractterm_id', 'businesstype_id', 'company', 'bcity', 'bphone', 'bstate', 'bstraddr',
            'bzip', 'firstname', 'lastname', 'mobile', 'hcity',
            'hphone', 'hstate', 'hstraddr', 'hzip'
        ]);

        $morepcs_array = \Input::only('addtpcmake','addtpcmodel','addtpcserial','addtpcname');
    /*  
        // Debugging Code
        foreach ($morepcs_array as $textbox_name => $textbox)
            {
                echo "<br><br>".$textbox_name;
                echo "<br>textbox quantity: ".sizeof($textbox);
                foreach($textbox as $value) {
                    if ($value == NULL) {
                        echo "<br>NULL";
                    }
                    else {
                        echo "<br>".$value;
                    }
                }
            }
    */  
        $customer = new customer($input); // Create new customer object. Store $input into this object.
        $computer = new computer; // Create new computer object
        $computer->addtpcs = \Input::get('addtpcs'); // Get the form data for addtpcs and prepare to store it in a database table named addtpcs.
        $computer->save(); // Save the information into the database table addtpcs from the computer object.
        $customer->computer()->associate($computer); // Using the associate function, store the id from the computer table in the database to the customer_id table in the database.
        $customer->save(); // send all of the data to the customer table in the database.

        // $startdate = new day;
        $startdate = \Input::get('contract_date');
        // $customer->startdate()->save($startdate);

        //Log::info('$startdate from controller before it is passed to the StoredProcedureCall method: ' . $startdate);
        //Log::info('$customer->id from controller before it is passed to the StoredProcedureCall method: ' . $customer->id);
        //Computer::storedProcedureCall($customer->id,$startdate);
        //$days = Day::all()->last(); // Never do this.  For testing purposes only.
        // Figure out total contract cost based upon Contract Term and Business Type
        computer::storedProcedureCall($customer->id,$startdate); // Call the MySQL stored procedure.
}

计算机php:

Class computer extends \Eloquent {
 protected $guarded = array();

 public function customer() {
    return $this->hasMany('App\Library\customer');
 }

 public static function storedProcedureCall($customer, $contract_date) {
         //Log::info('$contract_date after it is received from the controller: ' . $contract_date);
         //Log::info('$data after it is received from the controller: ' . $data);
         return \DB::statement('call POPULATE_DAYS_TABLE(' . $customer . ', "'.$contract_date.'")');
    }
 public static $rules = array();
  }

错误日志:

[2016-01-31 16:36:20] local.ERROR: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION cr_debug.ENTER_MODULE2 does not exist in C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php:390
Stack trace:
#0 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php(390): PDOStatement->execute(Array)
#1 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php(644): Illuminate\Database\Connection->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection), 'call POPULATE_D...', Array)
#2 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php(611): Illuminate\Database\Connection->runQueryCallback('call POPULATE_D...', Array, Object(Closure))
#3 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php(391): Illuminate\Database\Connection->run('call POPULATE_D...', Array, Object(Closure))
#4 [internal function]: Illuminate\Database\Connection->statement('call POPULATE_D...')

更多错误-相同的日志文件:

Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION cr_debug.ENTER_MODULE2 does not exist (SQL: call POPULATE_DAYS_TABLE(23, "01/29/2016")) in C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php:651
Stack trace:
#0 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php(611): Illuminate\Database\Connection->runQueryCallback('call POPULATE_D...', Array, Object(Closure))
#1 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\Connection.php(391): Illuminate\Database\Connection->run('call POPULATE_D...', Array, Object(Closure))
#2 [internal function]: Illuminate\Database\Connection->statement('call POPULATE_D...')
#3 C:\Apache24\B2B_Contracts\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(317): call_user_func_array(Array, Array)

共有2个答案

钮高朗
2023-03-14

由于对存储过程的调用很奇怪,您可以尝试将其传递到底层PDO对象中,如。。

$db = \DB::connection()->getPdo();
$stmt=$db->prepare($sql);
$stmt->bindParams($params);
$stmt->execute();

就像在本机PHP中一样。为简洁而编辑,但我希望你能理解

龚铭
2023-03-14

真的很奇怪,但是MySQL创建了一系列函数,这些函数被添加到了我的存储过程中,导致存储过程崩溃。

2016年1月2日更新:Shadow指出,额外的调试来自dbforge studio,几年前我确实下载了它来调试存储过程。但答案仍然是一样的。如果遇到此问题,请从备份还原、删除调试垃圾或重新安装调试软件。

这方面的一个例子是,存储过程应该是这样的:

实存储过程

BEGIN
SET contract_date = STR_TO_DATE(contract_date, '%m/%d/%Y'); /* Changes parameter sent it to an actual date */
SELECT DATE_FORMAT(contract_date, '%Y-%m-%d') INTO @start_date; /* Store proper date format for Contract End Dates */

修改MySQL存储过程

BEGIN
DECLARE cr_stack_depth INTEGER DEFAULT cr_debug.ENTER_MODULE2('POPULATE_DAYS_TABLE', 'contracts', 7, 100430)/*[cr_debug.1]*/;
CALL cr_debug.UPDATE_WATCH3('`customer_id`', `customer_id`, 'INT', cr_stack_depth)/*[cr_debug.2]*/;
CALL cr_debug.UPDATE_WATCH3('`contract_date`', `contract_date`, 'TEXT', cr_stack_depth)/*[cr_debug.2]*/;
CALL cr_debug.TRACE(4, 4, 0, 5, cr_stack_depth)/*[cr_debug.2]*/;
CALL cr_debug.TRACE(5, 5, 0, 59, cr_stack_depth)/*[cr_debug.2]*/;
SET contract_date = STR_TO_DATE(contract_date, '%m/%d/%Y');
CALL cr_debug.UPDATE_WATCH3('contract_date', contract_date, '', cr_stack_depth)/*[cr_debug.1]*/; /* Changes parameter sent it to an actual date */
CALL cr_debug.TRACE(6, 6, 0, 63, cr_stack_depth)/*[cr_debug.2]*/;
SELECT DATE_FORMAT(contract_date, '%Y-%m-%d') INTO @start_date;

解决这个问题的方法是删除MySQL中的存储过程,并从我拥有的备份中重新导入它们。如果没有备份,则必须手动删除添加到备份中的所有垃圾。

 类似资料:
  • 我们前面所学习的 MySQL 语句都是针对一个表或几个表的单条 SQL 语句,但是在数据库的实际操作中,经常会有需要多条 SQL 语句处理多个表才能完成的操作。 例如,为了确认学生能否毕业,需要同时查询学生档案表、成绩表和综合表,此时就需要使用多条 SQL 语句来针对这几个数据表完成处理要求。 存储过程是一组为了完成特定功能的 SQL 语句集合。使用存储过程的目的是将常用或复杂的工作预先用 SQL

  • 本文向大家介绍将列的值存储到MySQL存储过程的变量中,包括了将列的值存储到MySQL存储过程的变量中的使用技巧和注意事项,需要的朋友参考一下 要声明变量,请在MySQL存储过程中使用DECLARE。让我们首先创建一个表- 使用插入命令在表中插入一些记录- 使用select语句显示表中的所有记录- 这将产生以下输出- 这是创建存储过程并将上述表的列值存储在存储过程变量中的查询- 调用存储过程- 这

  • 问题内容: 这个问题是一个相当开放的问题。我已经将MS SQLServer的存储过程与经典的ASP和ASP.net一起使用了一段时间,并且非常喜欢它们。 我正在从事一个小型的业余项目,由于各种原因,LAMP路线已经消失。在MySQL和PHP5中使用存储过程有任何提示/技巧/陷阱或良好的起点吗?我的MySQL版本支持存储过程。 问题答案: 算了,它比PDO难用得多,应该已经删除了。的确,它引入了对m

  • 存储过程被创建后,就会一直保存在数据库服务器上,直至被删除。当 MySQL 数据库中存在废弃的存储过程时,我们需要将它从数据库中删除。 MySQL 中使用 DROP PROCEDURE 语句来删除数据库中已经存在的存储过程。语法格式如下: DROP PROCEDURE [ IF EXISTS ] <过程名> 语法说明如下: 过程名:指定要删除的存储过程的名称。 IF EXISTS:指定这个关键字,

  • 在实际开发过程中,业务需求修改的情况时有发生,所以修改 MySQL 中的存储过程是不可避免的。 MySQL 中通过 ALTER PROCEDURE 语句来修改存储过程。本节将详细讲解修改存储过程的方法。 MySQL 中修改存储过程的语法格式如下: ALTER PROCEDURE 存储过程名 [ 特征 ... ] 指定了存储过程的特性,可能的取值有: CONTAINS SQL 表示子程序包含 SQL

  • 主要内容:查看存储过程的状态,查看存储过程的定义创建好存储过程后,用户可以通过 SHOW ATATUS 语句来查看存储过程的状态,也可以通过 SHOW CREATE 语句来查看存储过程的定义。本节主要讲解查看存储过程的状态和定义的方法。 查看存储过程的状态 MySQL 中可以通过 SHOW STATUS 语句查看存储过程的状态,其基本语法形式如下: SHOW PROCEDURE STATUS LIKE 存储过程名; 用来匹配存储过程的名称,LI