简体   繁体   English

如何使用mysqli预准备语句将日期从PHP发送到MySQL存储过程参数

[英]How to send date from PHP to MySQL stored procedure parameter using mysqli prepared statement

PHP Code: PHP代码:

$stmt = $db->prepare("CALL `usp_AddRegistrationInfo`(?,?);");
        $stmt->bind_param('ss',$userID,$dob);
        $stmt->execute();

MYSQL Stored Procedure: MYSQL存储过程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `usp_AddRegistrationInfo`(IN `ID` VARCHAR(20), IN `date_of_birth` DATE)
BEGIN

INSERT INTO `tbl_userdetails` (`UserID`, date_of_birth);


END

In the above statements if I pass the date from PHP to MySQL its not working properly. 在上面的语句中,如果我将日期从PHP传递到MySQL,则无法正常工作。 For example if I send 1993-01-01 it is storing as 0000-00-00 . 例如,如果我发送1993-01-01其存储为0000-00-00 Please help me in this process. 请在这个过程中帮助我。

Thanks in advance. 提前致谢。

Hmmm... I would think that if $dob == '1993-01-01' , your code should work... but perhaps MySQL does not recognize $dob as a date. 嗯...我想如果$dob == '1993-01-01' ,您的代码应该可以工作...但也许MySQL无法将$ dob识别为日期。 Try this: 尝试这个:

$dob = date('Y-m-d', strtotime($dob));

$stmt = $db->prepare("CALL `usp_AddRegistrationInfo`(?,?);");
$stmt->bind_param('ss',$userID,$dob);
$stmt->execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM