Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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 将日期从PDO传递到MySQL存储过程_Php_Mysql_Sql_Stored Procedures_Pdo - Fatal编程技术网

Php 将日期从PDO传递到MySQL存储过程

Php 将日期从PDO传递到MySQL存储过程,php,mysql,sql,stored-procedures,pdo,Php,Mysql,Sql,Stored Procedures,Pdo,我即将结束从MSSQL到MySQL的转换过程,突然遇到了一个障碍。我有许多存储过程,通过PDO传递表单中的日期。这在MSSQL中运行良好,但现在导致MySQL版本崩溃 这就是我调用过程的方式:- $command = "CALL AddThis (?, ?, ?, ?)"; $stpro = $conn->prepare($command); $stpro->bindParam(1, $_POST['date'], PDO::PARAM_STR); $stpro->bindP

我即将结束从MSSQL到MySQL的转换过程,突然遇到了一个障碍。我有许多存储过程,通过PDO传递表单中的日期。这在MSSQL中运行良好,但现在导致MySQL版本崩溃

这就是我调用过程的方式:-

$command = "CALL AddThis (?, ?, ?, ?)";

$stpro = $conn->prepare($command);
$stpro->bindParam(1, $_POST['date'], PDO::PARAM_STR);
$stpro->bindParam(2, $_POST['type']);
$stpro->bindParam(3, $bool1, PDO::PARAM_BOOL);
$stpro->bindParam(4, $bool2, PDO::PARAM_BOOL);

// call the stored procedure

$returnvalue = $stpro->execute();
程序如下开始:-

PROCEDURE `AddThis `(
    IN this_date      date,
    IN this_type      nvarchar(50),
    IN bool1          bool,
    IN bool2          bool)
如果我完全删除了第一个变量,那么过程将启动并运行,没有问题。我一加上日期字段,整个事情就结束了


有什么建议吗?

好的,所以这可能不是最好的方法,但我已经设法让它发挥作用(返回我想要的答案)

我保持了php的原样

$stpro->bindParam(1, $_POST['date'], PDO::PARAM_STR);
但我已将SQL in语句更改为

IN this_date        nvarchar(10),
然后将这一行添加到程序主体中

SET     @datetouse = STR_TO_DATE(this_date, '%m,%d,%Y');
m/d/y是我在字符串中传递日期的格式,以“,”作为分隔符


正如我上面所说,这可能不是正确的方法,但它是有效的,所以我很高兴。哈哈哈

。。。整个事情都失败了!!发生了什么。如果出现错误,则进行堆栈后跟踪。$returnvalue=false。例如,程序没有运行。过程中的任何插入都不会运行。不运行意味着什么?是否引发任何异常?抓到了吗?没什么。即使只在存储过程中放置一个命令也不起作用。通过删除日期变量,尽管它运行并返回true。
$stpro->bindParam(1,date(“m-d-Y H:i:s”,strotime($\u POST['date'])),PDO::PARAM\u STR)