简体   繁体   中英

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

PHP Code:

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

MYSQL Stored Procedure:

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. For example if I send 1993-01-01 it is storing as 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. Try this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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