简体   繁体   English

如何在我的PHP查询代码中使用MySQL函数?

[英]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. 我正在尝试执行插入查询时将字符串“ date”值从提交的表单转换为实际日期。 I thought I could use the MySQL function str_to_date, but I'm getting an error message. 我以为可以使用MySQL函数str_to_date,但是却收到一条错误消息。

Here's my code; 这是我的代码; this is a Joomla site, so the JRequest::getVar calls are joomla's way of getting submitted _post variables. 这是一个Joomla网站,因此JRequest :: getVar调用是joomla获取提交的_post变量的方法。

$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. 我也尝试了不带$ db-> quote的birthdate行,但是遇到了同样的错误。 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. 其中第156行是包含str_to_date调用的行。 Any ideas? 有任何想法吗?

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

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

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

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