简体   繁体   中英

How can I use a MySQL function in my PHP query code?

I'm trying to convert a string "date" value from a submitted form into an actual date while doing my insert query. I thought I could use the MySQL function str_to_date, but I'm getting an error message.

Here's my code; this is a Joomla site, so the JRequest::getVar calls are joomla's way of getting submitted _post variables.

$query = "insert into jos_customers_addresses (customer_id,nickname,birthdate)
values ("
        .$db->quote($userAcctID).","
        .$db->quote($nickname).","
        .$db->quote(STR_TO_DATE(JRequest::getVar('birthdate'),'%m/%d/%Y'))
.")";

I've also tried the birthdate line without the $db->quote, but got the same error. The error message is:

Fatal error: Call to undefined function STR_TO_DATE() in /var/www/html/mysite.com/components/com_arrcard/models/checkoutpay.php on line 156

where line 156 is the line containing the str_to_date call. Any ideas?

将其放在查询中,而不是代码中。

."STR_TO_DATE(".$db->quote(JRequest::getVar('birthdate')).",'%m/%d/%Y')"

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