Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:中未定义参数_Php_Mysql_Stored Procedures - Fatal编程技术网

Php 警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:中未定义参数

Php 警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:中未定义参数,php,mysql,stored-procedures,Php,Mysql,Stored Procedures,我试图用php和mysql调用一个存储过程并得到上面的错误消息?有人知道我做错了什么吗 try{ $conn = new PDO('mysql:host=localhost;dbname=holidaybookingapp', '', ''); } catch (PDOException $exception) { echo "Oh no, there was a problem" . $exception->getMessage(); } $startDate="

我试图用php和mysql调用一个存储过程并得到上面的错误消息?有人知道我做错了什么吗

try{
   $conn = new PDO('mysql:host=localhost;dbname=holidaybookingapp', '', '');
}
catch (PDOException $exception) 
{
   echo "Oh no, there was a problem" . $exception->getMessage();
}

    $startDate="2017-05-23";
    $endDate="2017-05-23";
    $empID= "2";

    $sql='CALL spAddNewHoliday(:EmployeeID,:StartDate,:EndDate)';
    $stmt = $conn->prepare($sql);

    $stmt = $conn->prepare("CALL spAddNewHoloiday(?,?,?)");

    $stmt->bindParam('employeeID',$empID, PDO::PARAM_STR);
    $stmt->bindParam('StartDate1',$startDate, PDO::PARAM_STR);
    $stmt->bindParam('EndDate1',$endDate, PDO::PARAM_STR);
    //$array=array($empID, $startDate,$endDate);

    $stmt->execute(); // call the stored procedure
更改为:

$sql='CALL spAddNewHoliday(:EmployeeID,:StartDate,:EndDate)';
$stmt = $conn->prepare($sql);
致:

更改为:

$sql='CALL spAddNewHoliday(:EmployeeID,:StartDate,:EndDate)';
$stmt = $conn->prepare($sql);
致:


我会这样做:

$stmt = $conn->prepare("CALL spAddNewHoliday(:emp,:start,:end)");
$stmt->execute([':emp'=>$empID,':start'=>$startDate,':end'=>$endDate]);

我会这样做:

$stmt = $conn->prepare("CALL spAddNewHoliday(:emp,:start,:end)");
$stmt->execute([':emp'=>$empID,':start'=>$startDate,':end'=>$endDate]);
删除第二个prepare(),占位符必须匹配相同的名称

$startDate="2017-05-23";
$endDate="2017-05-23";
$empID= "2";

$sql='CALL spAddNewHoliday(:EmployeeID,:StartDate,:EndDate)';
$stmt = $conn->prepare($sql);

$stmt->bindParam('EmployeeID',$empID, PDO::PARAM_STR);
$stmt->bindParam('StartDate',$startDate, PDO::PARAM_STR);
$stmt->bindParam('EndDate',$endDate, PDO::PARAM_STR);

$stmt->execute(); // call the stored procedure
删除第二个prepare(),占位符必须匹配相同的名称

$startDate="2017-05-23";
$endDate="2017-05-23";
$empID= "2";

$sql='CALL spAddNewHoliday(:EmployeeID,:StartDate,:EndDate)';
$stmt = $conn->prepare($sql);

$stmt->bindParam('EmployeeID',$empID, PDO::PARAM_STR);
$stmt->bindParam('StartDate',$startDate, PDO::PARAM_STR);
$stmt->bindParam('EndDate',$endDate, PDO::PARAM_STR);

$stmt->execute(); // call the stored procedure

无效的参数编号似乎很清楚。。。为什么要准备两次stmt?顺便说一句,为什么不保留第一个stmt并在execute中使用数组而不是bindParam三次呢?+注意你的“spaddnewwholeday”看起来不对。。。(holoiday)您调用
prepare
两次。如果您像第一次一样调用
prepare
,则必须调用
bindParam(“:StartDate”…)
(末尾有
,没有
1
);如果您像第二种方式那样调用它,那么必须调用
bindParam(1,$empID,…);bindParam(2,$startDate…)等
无效参数编号似乎很清楚。。。为什么要准备两次stmt?顺便说一句,为什么不保留第一个stmt并在execute中使用数组而不是bindParam三次呢?+注意你的“spaddnewwholeday”看起来不对。。。(holoiday)您调用
prepare
两次。如果您像第一次一样调用
prepare
,则必须调用
bindParam(“:StartDate”…)
(末尾有
,没有
1
);如果您像第二种方式那样调用它,那么必须调用
bindParam(1,$empID,…);bindParam(2,$startDate…)等